L
Lloyd Dupont
When you define UserControl in source code the sample I see are often like
that:
============
public string Text
{
get
{
String s = (String)ViewState["Text"];
return ((s == null) ? String.Empty : s);
}
set
{
ViewState["Text"] = value;
}
}
============
Yet I found that this simpler approach work well
============
string text;
public string Text
{
get { return text; }
set { text = value; }
}
============
It also doesn't clutter the web page (as the view state is embeded in the
page as an input of HIDDEN type).
So now I wonder, why use the ViewState exactly?
I guess there are reason to do so, like if I want to programatically change
the control property with an event handler and keep on further post back.
Yet that looks to me as a very marginal exemple.
Are there better reason?
And how to mark a control in such a way that it won't store its view state
in the web page.
Such as: I use ViewState to store property (in case they need to be stored),
yet I doesn't output this viewstate to the web page, in case it doesn't need
to be restored (would be equal to value in the aspx)?
Yet that seems quite a marginal
that:
============
public string Text
{
get
{
String s = (String)ViewState["Text"];
return ((s == null) ? String.Empty : s);
}
set
{
ViewState["Text"] = value;
}
}
============
Yet I found that this simpler approach work well
============
string text;
public string Text
{
get { return text; }
set { text = value; }
}
============
It also doesn't clutter the web page (as the view state is embeded in the
page as an input of HIDDEN type).
So now I wonder, why use the ViewState exactly?
I guess there are reason to do so, like if I want to programatically change
the control property with an event handler and keep on further post back.
Yet that looks to me as a very marginal exemple.
Are there better reason?
And how to mark a control in such a way that it won't store its view state
in the web page.
Such as: I use ViewState to store property (in case they need to be stored),
yet I doesn't output this viewstate to the web page, in case it doesn't need
to be restored (would be equal to value in the aspx)?
Yet that seems quite a marginal