Public partial class Test: Web SitePage
{
Public int circleID;
Protected void Page_Load (object sender, System. EventArgs e)
{
CircleID=6;
}
Protected void bbt_Click (object sender, EventArgs e)
{
Int testID=circleID;
}
}
Results suggest testID is null, how can I get to circleID value?
CodePudding user response:
This is a web page when you load an instance, and then click on your page is will create a new instance, add a staticCodePudding user response:
Protected void Page_Load (object sender, System. EventArgs e)
{
if(! Ispostpaback) {
CircleID=6;
}
}
CodePudding user response:
The static static, constant, and I need to modify the value of this variable in the Page_Load,CodePudding user response:
Are you sure you don't get?
Int testID=circleID;
Response. Write (testID);
Const with static readonly is read-only constant, and the static modifier field method, on behalf of you don't have to instantiate the class is invoked directly, you this is the web page, unless to share this value, just use the static, a user changes the value, another user's value will also get this value
CodePudding user response:
My first reaction, is also described in # 2,you try.if(! Ispostpaback) {
CircleID=6;
}
CodePudding user response:
On the page with aotopost=true runat=serverYou'd better put in the session, and not page member variables
CodePudding user response:
Add the staticCodePudding user response:
Are you sure you can't get? Describes your scene clearly, will you give the code, button_click output fine inside,CodePudding user response:
The old "web server page development" every page postback handling, actually is a new application is started, if you want to cross the Request process data access page should use view state framework mechanism,CodePudding user response:
Use Session collection is inappropriate, view state is according to the local data page, while the Session is according to the global web site each page;CodePudding user response:
A casual (roughly) writing, this kind of code we have 10 years don't write:private int _circleID;
Public int circleID
{
The get {
Var v=view state (" cID ");
Return v==null? Zero: (int) v.
}
The set {
View state [" cID "]=value;
}
}
Asp.net development strong again, even if its technology which time will stay in 2006, since 2013 web front-end gradually developed to a very large and comprehensive technology, the front end of the suggestion to learn modern technology, it goes with c #, Java, PHP or python and so on all has nothing to do, including Microsoft typescript as a front end technology at the bottom of the common base, a little bit,
CodePudding user response:
Look at the WebPage of the life cycle, as a Post back page is not running the Load event,CodePudding user response:
No problem, I read your code output is normal, you can output a null, page every button to assign a value, both add do not add ispostpaback should be no problem, I tried 2 times, debug output is no problem,CodePudding user response:
If the current page, with the use of view state preserved value, so it can get circleID assignment and the value of thepublic int circleID
{
The get
{
Return the view state [" circleID "]==null? Zero: (int) view state [" circleID "];
}
Set
{
View state [" circleID "]=value;
}
}