first of all i must say that i'm new to asp.net.. and i'm not english native speaker so sorry for my poor english :)
i created simple site where can add some textboxes to updatepanel
when "add textbox" button is clicked, in updatepanel appears a textbox and button (which allows to remove that textbox)
first question:
is it possible to find out which "remove" button has been clicked in e.g. page_init or page_load method
and then (in this method) remove appropriate textbox and button itself?
i tried to do it in some ways but i couldn't handle it
second question/problem:
when i uncomment in e.g. page_load method those lines:
protected void Page_Load(object sender, EventArgs e)
{
// uncomment and run again
//Label1.Text += " !!!!!!! text added in page_load method to label inside UpdatePanel";
//Label2.Text += " !!!!!!! text added in page_load method to label outside UpdatePanel";
}
i get some error :/
first label is located inside updatepanel, and second outside it, but i noticed that is not important where that label is positioned
to cause that error you have to:
! dont forget to uncomment that code ;)
open this site in browser - site must be loaded from server, not from cache - just in case put site adress in address bar and hit enter
click "add textbox"
refresh site - f5 in browser or press "refresh button" in browser
using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; public partial class Default2 : System.Web.UI.Page { static ArrayList alNameId; private string nameNameTextBox="nameTextBox"; private string nameNameRemoveButton = "nameRemoveButton"; private string nameNamePanel = "namePanel"; protected void Page_PreInit(object sender, EventArgs e) { Control postBackControl = GetPostBackControl(this.Page); if (!this.Page.IsPostBack) { alNameId = new ArrayList(); alNameId.Add(1); } if (postBackControl != null) { if ((postBackControl.ClientID.ToString() == buttonAddTextBoxes.ID.ToString())) { int biggestNr = (int)alNameId[alNameId.Count - 1]; biggestNr++; alNameId.Add(biggestNr); }
} } protected void Page_Init(object sender, EventArgs e) {
TextBox tbox = new TextBox(); tbox.ID = nameNameTextBox + alNameId[0]; Panel pa = new Panel(); pa.ID = nameNamePanel + alNameId[0]; pa.Controls.Add(tbox); placeHolderTextBoxes.Controls.Add(pa); if(alNameId.Count>1) for (int i = 1; i < alNameId.Count; i++) { TextBox tb = new TextBox(); tb.ID = nameNameTextBox + alNameId[i]; Button rb = new Button(); rb.ID = nameNameRemoveButton + alNameId[i]; rb.Text = "remove " + alNameId[i]; rb.Click += new EventHandler(rbButon_Click); Panel p = new Panel(); p.ID = nameNamePanel + alNameId[i];
p.Controls.Add(tb); p.Controls.Add(rb); placeHolderTextBoxes.Controls.Add(p); } } protected void Page_Load(object sender, EventArgs e) { // uncomment and run again ********************* !!!!!!!!!!!!!! ************************************* //Label1.Text += " !!!!!!! text added in page_load method to label inside UpdatePanel";
//Label2.Text += " !!!!!!! text added in page_load method to label outside UpdatePanel";
} protected void rbButon_Click(object sender, EventArgs e) { string name=((Button)sender).ClientID; int removeNr = Int32.Parse(name.Substring(nameNameRemoveButton.Length, name.Length - nameNameRemoveButton.Length)); alNameId.Remove(removeNr); placeHolderTextBoxes.Controls.Remove(placeHolderTextBoxes.FindControl(name)); placeHolderTextBoxes.Controls.Remove(placeHolderTextBoxes.FindControl(nameNameTextBox + removeNr.ToString())); placeHolderTextBoxes.Controls.Remove(placeHolderTextBoxes.FindControl(nameNamePanel + removeNr.ToString()));
} protected void buttonAddTextBoxes_Click(object sender, EventArgs e) { } public static Control GetPostBackControl(Page thePage) { Control myControl = null; string ctrlName = thePage.Request.Params.Get("__EVENTTARGET"); if (((ctrlName != null) & (ctrlName != string.Empty))) { myControl = thePage.FindControl(ctrlName); } else
{ foreach (string Item in thePage.Request.Form) { Control c = thePage.FindControl(Item); if (((c) is System.Web.UI.WebControls.Button)) { myControl = c; } }
} return myControl; }
}
web config file:
<!-- Note: As an alternative to hand editing this file you can use the web admin tool to configure settings for your application. Use the Website->Asp.Net Configuration option in Visual Studio. A full list of settings and comments can be found in machine.config.comments usually located in \Windows\Microsoft.Net\Framework\v2.x\Config -->
<configuration>
<configSections> <sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"> <sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"> <section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/> <sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"> <section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere"/> <section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/> <section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/> <section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/> </sectionGroup> </sectionGroup> </sectionGroup> </configSections> <appSettings/> <connectionStrings> <!-- <add name="NorthwindConnectionString" connectionString="Data Source=;Initial Catalog=Northwind;Persist Security Info=True;" providerName="System.Data.SqlClient"/> -->
<add name="NorthwindConnectionString" providerName="System.Data.SqlClient" connectionString="server=.\SQLEXPRESS;database=Northwind;Integrated Security=SSPI" /> </connectionStrings> <system.web> <!-- Set compilation debug="true" to insert debugging symbols into the compiled page. Because this affects performance, set this value to true only during development. -->
<compilation debug="true"> <assemblies> <add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/> <add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> <add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/> <add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/> <add assembly="System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/> <add assembly="System.Web.Extensions.Design, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> <add assembly="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/></assemblies> </compilation> <!-- The <authentication> section enables configuration of the security authentication mode used by ASP.NET to identify an incoming user. -->
<authentication mode="Windows"/> <!-- The <customErrors> section enables configuration of what to do if/when an unhandled error occurs during the execution of a request. Specifically, it enables developers to configure html error pages to be displayed in place of a error stack trace.
<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm"> <error statusCode="403" redirect="NoAccess.htm" /> <error statusCode="404" redirect="FileNotFound.htm" /> </customErrors> -->
<pages> <controls> <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> <add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> </controls> </pages> <httpHandlers> <remove verb="*" path="*.asmx"/> <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false"/> </httpHandlers> <httpModules> <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> </httpModules> </system.web> <system.codedom> <compilers> <compiler language="c#;cs;csharp" extension=".cs" warningLevel="4" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <providerOption name="CompilerVersion" value="v3.5"/> <providerOption name="WarnAsError" value="false"/> </compiler> <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" warningLevel="4" type="Microsoft.VisualBasic.VBCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <providerOption name="CompilerVersion" value="v3.5"/> <providerOption name="OptionInfer" value="true"/> <providerOption name="WarnAsError" value="false"/> </compiler> </compilers> </system.codedom> <!-- The system.webServer section is required for running ASP.NET AJAX under Internet Information Services 7.0. It is not necessary for previous version of IIS. -->
<system.webServer> <validation validateIntegratedModeConfiguration="false"/> <modules> <remove name="ScriptModule"/> <add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> </modules> <handlers> <remove name="WebServiceHandlerFactory-Integrated"/> <remove name="ScriptHandlerFactory"/> <remove name="ScriptHandlerFactoryAppServices"/> <remove name="ScriptResource"/> <add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> <add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> <add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> </handlers> </system.webServer> <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="System.Web.Extensions" publicKeyToken="31bf3856ad364e35"/> <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Web.Extensions.Design" publicKeyToken="31bf3856ad364e35"/> <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/> </dependentAssembly> </assemblyBinding> </runtime> </configuration>
ERROR :/
Server Error in '/' Application.
The state information is invalid for this page and might be corrupted.
Description:
An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details:
System.Web.HttpException: The state information is invalid for this page and might be corrupted.
Source Error:
[No relevant source lines]
Source File: c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\3e0e8054\12e1c492\App_Web_985ndyxm.2.cs
i noticed that similar error occurres when i press "add textbox" instead of "postback button"
when i press "postback button" i get error message on page, and when "add textbox" nothing happens "visually", but Firebug says that the same error occurres
it's something like that:
server error code(?) 500, and information: The state information is invalid for this page and might be corrupted.
and what about detecting in e.g page_init method which "remove" button was clicked?
HI lachlankeown, what you suggest is correct regarding changing the formid will fix the problem however using ASP.NET 3.5 C# setting the form ID the formID alwasy comes up as "aspnetForm" no matter where you specify it (Init, Load, PreRender etc),
what we ended up doing is in the pageLoaded Ajax event is then changing both the forms id & name, and this seems to have fixed it...
Hi, thanks for the info. On further investigation it seems that this is the case when using a Master Page - you can't programmatically alter the form ID. You CAN alter it in a standard .aspx page. I'll add your workaround to my page, thanks!
poiuymn
Member
1 Points
7 Posts
browser refresh, viewstate and updatepanel problem
Apr 23, 2008 08:37 PM|LINK
hello
first of all i must say that i'm new to asp.net.. and i'm not english native speaker so sorry for my poor english :)
i created simple site where can add some textboxes to updatepanel
when "add textbox" button is clicked, in updatepanel appears a textbox and button (which allows to remove that textbox)
first question:
is it possible to find out which "remove" button has been clicked in e.g. page_init or page_load method and then (in this method) remove appropriate textbox and button itself?
i tried to do it in some ways but i couldn't handle it
second question/problem:
when i uncomment in e.g. page_load method those lines:
how to get rid of that error?
what do i do wrong?
here is application code:
web config file:
ERROR :/
Server Error in '/' Application.
The state information is invalid for this page and might be corrupted.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Web.HttpException: The state information is invalid for this page and might be corrupted.
Source Error:
Maheshpandian
Member
8 Points
10 Posts
Re: browser refresh, viewstate and updatepanel problem
Apr 24, 2008 06:12 AM|LINK
http://projectcreatersworld.blogspot.com check this page for view state it helped me a lot
poiuymn
Member
1 Points
7 Posts
Re: browser refresh, viewstate and updatepanel problem
Apr 24, 2008 01:28 PM|LINK
thanks for your reply
i checked that site, but it didnt help
i really dont know what is wrong with this code
i noticed that similar error occurres when i press "add textbox" instead of "postback button"
when i press "postback button" i get error message on page, and when "add textbox" nothing happens "visually", but Firebug says that the same error occurres
it's something like that:
server error code(?) 500, and information: The state information is invalid for this page and might be corrupted.
and what about detecting in e.g page_init method which "remove" button was clicked?
anyone knows?
lachlankeown
Member
12 Points
6 Posts
Re: browser refresh, viewstate and updatepanel problem
Apr 29, 2008 09:15 AM|LINK
Hi, I'm pretty sure this looks like the same problem I was having.
Check out my workaround I wrote up on my blog...
http://lachlankeown.blogspot.com/2008/04/firefox-refresh-viewstate-updatepanel.html
Cheers
danman1977
Member
10 Points
8 Posts
Re: browser refresh, viewstate and updatepanel problem
May 15, 2008 10:26 PM|LINK
HI lachlankeown, what you suggest is correct regarding changing the formid will fix the problem however using ASP.NET 3.5 C# setting the form ID the formID alwasy comes up as "aspnetForm" no matter where you specify it (Init, Load, PreRender etc), what we ended up doing is in the pageLoaded Ajax event is then changing both the forms id & name, and this seems to have fixed it...
Dan
lachlankeown
Member
12 Points
6 Posts
Re: browser refresh, viewstate and updatepanel problem
May 15, 2008 10:41 PM|LINK
pareshjagatiya
Member
516 Points
89 Posts
Re: browser refresh, viewstate and updatepanel problem
May 26, 2008 09:33 AM|LINK
This is surely the FireFox fields caching issue.
add this code into your page
protected override void OnPreInit(EventArgs e)
{
base.OnPreInit(e);
if (Request.Browser.MSDomVersion.Major == 0) // If it is Non IE Browser
{
Response.Cache.SetNoStore();
}
}
- Regards,
Paresh Jagatia
http://pareshjagatia.blogspot.com