Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Mantain ViewState

Reply
Thread Tools

Mantain ViewState

 
 
Jonathan
Guest
Posts: n/a
 
      03-09-2005
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.GetPostBackCl ientEvent(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);
}
}
}

Somebody knows how is the correct way to mantain the ViewState

Thanks!


 
Reply With Quote
 
 
 
 
=?Utf-8?B?VmlzYXIgR2FzaGk=?=
Guest
Posts: n/a
 
      03-09-2005
From the code that you have displayed, it looks that you are using the
ViewState ok, although you are doing things the hard way. You can, instead,
just create a button and a text box and handle the button event without
worrying about postbacks.

Two things you should look for. First, make sure you have the ViewState
enabled (you can check by Page.EnableViewState). Second, make sure that your
page is not being posted back more than once or re-directed. Best way to look
for that is to enable tracing on the containing page. You should then be able
to see if the page posted back once or more times. You will also be able to
see the size of the viewstate for each control.

Regards,
-Visar

"Jonathan" wrote:

> 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.GetPostBackCl ientEvent(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);
> }
> }
> }
>
> Somebody knows how is the correct way to mantain the ViewState
>
> Thanks!
>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Mantain IDE colors and paste them in an HTML page billie Python 3 10-05-2005 06:02 AM
How to mantain the state between 2 call of the same WebService? Alessandro Benedetti ASP .Net Web Services 13 03-17-2005 05:38 PM
Mantain Property Mike ASP .Net Web Controls 1 03-14-2005 04:47 PM
Mantain Property Mike ASP .Net Building Controls 1 03-14-2005 03:35 PM
Mantain ViewState Jonathan ASP .Net Web Controls 0 03-10-2005 12:25 PM



Advertisments