c# - Pass objects/vars between Page_PreInit and Page_Load -
I use the database to store page information and .NET (C #) I am creating pages from the form. Part of the process is to set the master-page (code-back) on the basis of what is in the database, and as I think, it has to be done in Page_PreInit
.
My problem is how to pass objects and variables from Page_PreInit
to Page_Load
.
I am able to do it in this way, but I am using this method when doing random compiling errors:
The public partial category BuildPage: System .Web.UI.Page {protected static string pageData; Protected Zero Page_PreInit (Object Sender, EventArgs E) {--- SET pageData = Data from database, and set masterpages ---} Safe page page (Location sender, EventArgs e) To secure - For different purposes, I I'm not using Visual Studio to compile, just want to give a .NET compilation on the first page request on the flight. I have received two error messages: 1) "CS0102: 'buildpages' type already has a definition for 'pageddata'"
2) "ASPnet: Ensure Make sure that the square matches the 'legacy' attribute defined in this code file, and it extends to the right base class (such as page or user control). "
The odd thing is that sometimes the web page Requests on the server. And, for the time that it is not on the first request, when a random number of the page is refreshed, it will compile it completely. After compiling it all works fine until I do another change in the code behind it and it has to be compiled again.
I think that while getting those compilation errors, using that method, Page_PreInit
and Page_load
. In other words, if I request data from the database twice, once in 'Page_PreInit' and 'Page_load' I never get those errors, but I really do not want to double the database load.
So my question really has two parts, first of all, that variables are an acceptable way of sharing or it is from Page_PreInit
to Page_load
?
And secondly, if this is an acceptable way, errors are unrelated and someone has seen errors that are just before repetitive web requests?
Thanks for any and all help! Fodder [/ b]
class. However, your member should not still
. Static
means that there is a single example in multiple threads. Every copy of that page, which is being executed for various requests reaching that page, is competing to read / write that member. In addition to this, your class is marked "partial", that means another file can contain another square piece, which has additional members and methods for that BuildPage
If the class declares you both the same pageadata member, they will fight.
Comments
Post a Comment