473,382 Members | 1,437 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Mantain ViewState

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!
Nov 19 '05 #1
1 2299
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!

Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: John Kirksey | last post by:
I have a page that uses an in-place editable DataGrid that supports sorting and paging. EnableViewState is turned ON. At the top of the page are several search fields that allow the user to filter...
3
by: Steve Drake | last post by:
All, I have a CONTROL that contains 1 control (Control ONE), the 1 control that it can contain 1 or 2 control (Control A and B). Control A, raises and event and Control ONE receives this event...
10
by: neo | last post by:
hi, I am studying ASP.NET and have few questions - 1) The session ID and values of controls is stored in VIEWSTATE variable. So now when we put EnableViewState="false" in Page directive and...
1
by: Simon | last post by:
Hi everyone, I have a quick question that I hope someone can help me with: I've made a user control that contains a text box and some validation functionality. This control has a few extra...
7
by: et | last post by:
I'm not sure I understand the use of the ViewState. Do I understand correctly that values of controls are automatically held in a hidden control called ViewState? If so, then why can't we get...
9
by: Mark Broadbent | last post by:
Been a while since I've touched asp.net but one thing that always seems to fustrate me is the loss of state on variable declarations. Is there anyway (i.e. assigning an attribute etc) to instruct...
0
by: cdani | last post by:
Hello. I have an applicattion with visual basic.net, which uses windows forms. How can I mantain a session in different calls to the same webservice? (which uses some database access). The goal...
6
by: hitendra15 | last post by:
Hi I have created web user control which has Repeater control and Linkbutton in ItemTemplate of repeater control, following is the code for this control On first load it runs fine but when...
12
by: Nick C | last post by:
Hi How can i reduce the viewstate for my asp.net application. It is getting very large now. What is a good solution? thanks N
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.