I build a control,there has a property name JsDirectory
it's default value is "/g_Scripts/"
when using this control in a web form,I change the
JsDirectory in the Property designer
to "../g_scripts/",and then it runs well at once,but when
I postback,and try to using this property inside a button
click event,I found the prpoerty value is back to the
default one!!!
is this one bug of framework 1.0.3705?
but values it will keep and runs well every times,any
suggestion? many thanks....
webgenie - 17 Sep 2003 10:11 GMT
Hi matt.
i think your control works correctly.
because post back process reload your web form page.
any elements of html form has a default values when the page is reloaded.
post back is same.
any web form controls in .net base class library, use a ViewState object to keep there values.
so your control have to use ViewState object too.
sample code is here:
public string JsDirectory {
get {
if (Page.EnableViewState) {
if ((Page.ViewState["jsdir"] != null) && (Page.ViewState["jsdir"] != string.Empty))
return Page.ViewState["jsdir"];
else
return m_strJsDir;
}
else
return m_strJsDir;
}//end of get
set {
if (Page.EnableViewState) {
if (Page.ViewState["jsdir"] != null)
Page.ViewState["jsdir"] = value;
else
Page.ViewState.Add("jsdir", value);
m_strJsDir = value;
}
else
m_strJsDir = value;
}
}//end of property JsDirectory
private void Class1() {
if (Page.EnableViewState) {
if ((Page.ViewState["jsdir"] != null) && (Page.ViewState["jsdir"] != string.Empty))
m_strJsDir = Page.ViewState["jsdir"];
else
m_strJsDir = "/g_Scripts/";
}
else
m_strJsDir = "/g_Scripts/";
}//end of constructor
- webgenie
msn messenger : geniex@msn.com
matt alex - 17 Sep 2003 11:22 GMT
maybe you misunderstand what I mean...
If I use code like the one you describe above,it works correctly,but If
I use the Property Window to change the property JsDirectory,and run
it,it will work when not postback,but error when postback!!!
I don't know how to explain,some kinds of characters in the property
Window won't keep it's value!!!