iam having 1 textbox in my aspx page and one HTML button
when i call page for first time iam setting value of textbox in page_load this time my textbox is ok (not null) but when i click on HTML button which cause's Ajax call javascript to code behind ... so there that method which is called from ajax is showing my
textbox is null when iam trying to access its previous value
for dynamically generated controls your values will be preserved across postbacks via view state, you just have to make sure that you regenerate the control (with the same Id) prior or on the load event of your form. Most likely the reason for your values
resetting is that you are rebinding the controls on every post back with fresh data.
You only have to populate your controls with data the first time the page loads, then you just have to regenerate the controls with the same id when IsPostback equals true
kakanisantos...
Member
2 Points
4 Posts
TextBox controls are null on Ajax postback
May 04, 2012 03:34 PM|LINK
HI friends
i got small problem with my code
iam having 1 textbox in my aspx page and one HTML button
when i call page for first time iam setting value of textbox in page_load this time my textbox is ok (not null) but when i click on HTML button which cause's Ajax call javascript to code behind ... so there that method which is called from ajax is showing my textbox is null when iam trying to access its previous value
page_load()
{
if (!IsPostBack)
{
this.MyTextBox1.Text = "HI"; // this works fine
}
}
//ajax method
[AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
public string Callme()
{
String X = this.MyTextBox1.Text; // here it throws eror saying MyTextBox1 is null
}
so how to maintain value between normal request and Ajax postback
please help me out
chetan.sarod...
All-Star
65839 Points
11163 Posts
Re: TextBox controls are null on Ajax postback
May 07, 2012 03:23 AM|LINK
http://stackoverflow.com/questions/705615/asp-net-best-way-to-retain-label-text-value-between-postback-with-pagemethods
for dynamically generated controls your values will be preserved across postbacks via view state, you just have to make sure that you regenerate the control (with the same Id) prior or on the load event of your form. Most likely the reason for your values resetting is that you are rebinding the controls on every post back with fresh data.
You only have to populate your controls with data the first time the page loads, then you just have to regenerate the controls with the same id when IsPostback equals true
http://weblogs.asp.net/infinitiesloop/archive/2006/08/03/Truly-Understanding-Viewstate.aspx
http://weblogs.asp.net/infinitiesloop/archive/2006/08/25/TRULY-Understanding-Dynamic-Controls-_2800_Part-1_2900_.aspx
Senior Software Engineer,
Approva Systems Pvt Ltd, Pune, India.