Web Custom Control
-
I have a control that is: public class MyControl : System.Web.UI.WebControls.WebControl, IPostBackDataHandler, IPostBackEventHandler { ... } And it's method: protected override void Render(HtmlTextWriter output) { textbox1.RenderControl(output); base.Render(); } perfect... but now is the problem... when a write any word on my textbox and send a postback my textbox is cleared... I tried to implements the LoadPostData but it's never fired. I tried to sets an UniqueID and call Page.RegisterRequiresPostBack but its still doesn't working... any idea? Tkx.... Wender Oliveira .NET Programmer
-
I have a control that is: public class MyControl : System.Web.UI.WebControls.WebControl, IPostBackDataHandler, IPostBackEventHandler { ... } And it's method: protected override void Render(HtmlTextWriter output) { textbox1.RenderControl(output); base.Render(); } perfect... but now is the problem... when a write any word on my textbox and send a postback my textbox is cleared... I tried to implements the LoadPostData but it's never fired. I tried to sets an UniqueID and call Page.RegisterRequiresPostBack but its still doesn't working... any idea? Tkx.... Wender Oliveira .NET Programmer
Wender, 1) make sure you keep a reference to the textbox around. 2) although you don't show it, I suspect the issue is with when you create the text box. Try:
public class MyControl : System.Web.UI.WebControls.WebControl, INamingContainer { private Textbox txt1; ... protected override CreateChildControls(){ this.txt1 = new Textbox(); } protected override void Render(HtmlTextWriter output) { this.EnsureChildControls(); base.Render(); } }
Hope this helps, Bill
-
I have a control that is: public class MyControl : System.Web.UI.WebControls.WebControl, IPostBackDataHandler, IPostBackEventHandler { ... } And it's method: protected override void Render(HtmlTextWriter output) { textbox1.RenderControl(output); base.Render(); } perfect... but now is the problem... when a write any word on my textbox and send a postback my textbox is cleared... I tried to implements the LoadPostData but it's never fired. I tried to sets an UniqueID and call Page.RegisterRequiresPostBack but its still doesn't working... any idea? Tkx.... Wender Oliveira .NET Programmer
So... if someone need this someday here is the answer... Postback only works for the object with the same UniqueID... so... I was with 2 textboxes inside a same control... each textbox with an ID... so I found 2 ways to solve this... solution 1) set the id of each textbox with the same this.UniqueID. So when postback works it will find the 2 posted values in just one key with the 2 values... the event seems like this: string[] vals = values[postDataKey]; string val1 = vals[0]; string val2 = vals[1]; solution 2) I'm using this... I created an hidden textbox with Id equals to this.UniqueID just to fire the loadpostdata event and I set the textboxes values like textbox1.ID = this.UniqueID+":txt1"; textbox2.ID = this.UniqueID+":txt2"; so event would be: string val1 = values[this.UniqueID+":txt1"]; string val2 = values[this.UniqueID+":txt2"]; So... that's all... Wender Oliveira .NET Programmer