protected System.Web.UI.WebControls.RadioButtonList rblSymbols;
protected System.Web.UI.WebControls.CheckBox chkPublish;
protected System.Web.UI.WebControls.DropDownList ddlSubject;
protected System.Web.UI.WebControls.TextBox txtEntry;
protected System.Web.UI.WebControls.Button btnSave;
The btnSave_Click(object sender, System.EventArgs e) is properly registered in the InitializeComponent() method. Inside the btnSave_Click() method, I call another function to save to the db which works fine. However, when I attempt to reference the values of those items, they are not set properly. It's as if the IPostBackDataHandler.LoadPostData() method in the Init of the page lifecycle is not being done at all. Any ideas? So far, I have had to result to the following until this is figured out:
YUCK!:
**********************
myObj.Entry = Request["txtEntry"];
Preferred:
**********************
myObj.Entry = txtEntry.Text;
Thanks in advance for any insight you might have.
--ChadIs it possible you've disabled Viewstate at some point?
Peter,
Yes, itIS possible. In fact, I have done just that on several of my controls. Is this the problem? I will try re-enabling. I have read so much on the pros and cons of keeping it turned on. Is is safe to assume that if I wish to program as described above, I need to keep viewstate enabled?
--Chad
Heh... yeah, that could be the problem :)
ViewState is the mechanism by which your controls' properties are persisted across postbacks. If you want to grab myControl.Text, for example, you must have Viewstate enabled.
On the other hand, if you don't mind grabbing values from the Request.Form collection, you can kill Viewstate with impunity.
Cheers,
Peter - thanks for clearing this up for me! Very helpful!
--Chad
0 comments:
Post a Comment