Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Web Custom Control

Web Custom Control

Scheduled Pinned Locked Moved ASP.NET
csharpdesignhelpquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    Wender Oliveira
    wrote on last edited by
    #1

    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

    B W 2 Replies Last reply
    0
    • W Wender Oliveira

      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

      B Offline
      B Offline
      Bill Dean
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • W Wender Oliveira

        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

        W Offline
        W Offline
        Wender Oliveira
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups