Mantain ViewState

Discussion in 'ASP .Net Web Controls' started by Jonathan, Mar 10, 2005.

  1. Jonathan

    Jonathan Guest

    Hello,
    I'm writed a WebCustomControl but I can't mantain the viewstate. This is the
    code of my WebCustomContol:

    public class WebCustomControl1 : System.Web.UI.WebControls.WebControl,
    IPostBackEventHandler
    {
    public event EventHandler DoPostBack;
    protected override void Render(HtmlTextWriter output)
    {
    output.Write(GetControlHTML());
    }
    private string GetControlHTML()
    {
    StringWriter TextBoxWriter = new StringWriter();
    HtmlTextWriter ControlWriter = new HtmlTextWriter(TextBoxWriter);
    TextBox box = new TextBox();
    box.ID = "txtViewState";
    if(ViewState["txtViewState"] == null)
    ViewState.Add("txtViewState","Testeando");
    box.Text = (string)ViewState["txtViewState"];
    box.RenderControl(ControlWriter);
    Button button = new Button();
    button.Text = "DoPostBack";

    button.Attributes.Add("onclick",Page.GetPostBackClientEvent(button,"doPostBa
    ck"));
    button.RenderControl(ControlWriter);
    return TextBoxWriter.ToString();
    }
    public void RaisePostBackEvent(string eventArgument)
    {
    if(eventArgument == "doPostBack")
    {
    if(this.DoPostBack != null)
    this.DoPostBack(this,EventArgs.Empty);
    }
    }
    }

    * The Page.EnableViewState is true

    Somebody knows how is the correct way to mantain the ViewState?

    Thanks!
    Jonathan, Mar 10, 2005
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jonathan

    Mantain ViewState

    Jonathan, Mar 9, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    413
    =?Utf-8?B?VmlzYXIgR2FzaGk=?=
    Mar 9, 2005
  2. billie
    Replies:
    3
    Views:
    290
    Sybren Stuvel
    Oct 5, 2005
  3. Mike

    Mantain Property

    Mike, Mar 14, 2005, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    99
  4. Mike

    Mantain Property

    Mike, Mar 14, 2005, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    96
    Brock Allen
    Mar 14, 2005
  5. Alessandro Benedetti

    How to mantain the state between 2 call of the same WebService?

    Alessandro Benedetti, Mar 17, 2005, in forum: ASP .Net Web Services
    Replies:
    13
    Views:
    210
    Brock Allen
    Mar 17, 2005
Loading...

Share This Page