Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Building Controls / September 2003

Tip: Looking for answers? Try searching our database.

why property will change back to default?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
matt - 15 Sep 2003 08:36 GMT
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!!!

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.