There is a check method in checklogin. CS:
Public static void check (page apage)
{
If (apage. session ["OK"] = NULL | apage. session ["OK"]. tostring ()! = "OK ")
{
Apage. response. Redirect ("login. aspx ");
}
}
The correct method called on the master page:
Protected void page_init (Object sender, eventargs E)
{
Checklogin. Check (this. Page );
}
Cause:
Execution sequence of master pages and content pages:
1. init of the control in the master page;
2. init of the Content Page Control;
3. init of the master page;
4. init of the content page;
5. Load of the content page;
6. Load the master page;
7. Load of controls on the content page;
8. prerender on the content page;
9. prerender on the master page;
10. prerender of the master page control;
11. prerender of the control on the Content Page
Error Method:
1. checklogin. Check (mypage );
Running: An error occurred while converting the masterpage class to the page class.
2. Page mypage = new page ();
Checklogin. Check (mypage );
Run: system. Web. httpexception: the response is unavailable in this context.
3. Use the custom control masterpublicmethod. ascx to call the check method.
Protected void page_load (Object sender, eventargs E)
{
Checklogin. Check (this. Page );
}
Add the control to the master page: <uc1: masterpublicmethod id = "masterpublicmethod1" runat = "server"> </uc1: masterpublicmethod>
This method is changed to: In the page_load event of the master page: checklogin. Check (this. Page );
Running: normal
Cause of error: event execution sequence: page_load event on the Content Page-> page_load event on the master page. Check whether you have logged on to the page at the beginning.
4. Master page:
Protected void page_load (Object sender, eventargs E)
{
// Response. Write ("master ");
Checklogin. Check (this. Page );
}
Page_loadcomplete event on the Content Page:
Protected void page_loadcomplete (Object sender, eventargs E)
{
Int T, bid;
// Initialize parameters for Custom Controls
Pg = convert. toint32 (request. querystring ["PG"]);
Bid = convert. toint32 (request. querystring ["ID"]);
T = convert. toint32 (request. querystring ["T"]);
Switch (t)
{
Case 1:
// Reply
Break;
Case 2:
// Modify the reply
Break;
Case 3:
// Hide
Hidebook (BID );
Break;
Case 4:
// Delete
Delbook (BID );
Break;
}
}
Reason for modification: Page execution sequence: page_load on the Content Page-> page_load on the master page-> page_loadcomplete on the Content Page
Run: An error occurred while assigning values to variables in the custom control.
Error cause: some content pages contain custom controls, and the page_load event of custom controls contains code. The parameters of custom controls are initialized in the page_loadcomplete event of the Content Page.
Execution sequence of page_load: Content page_load-> master page_load-> Custom Control page_load-> content page_loadcomplete