why property will change back to default?

M

matt

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....
 
W

webgenie

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 : (e-mail address removed)
 
M

matt alex

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!!!
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top