An error about cross-page transfer in ASP. NET Advanced Programming

Source: Internet
Author: User

I bought this book yesterday and found one of the errors. On page 1, I modified this code, slightly different. The following code is available in privious. aspx.

 

<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title ID = "title1" runat = "server"> No title page </title>
<Style type = "text/CSS">
# Container {
Border: 1px solid #333333;
Width: 500px;
Margin: 0px auto;
}
# Left {
Width: 80%;
Float: left;
}
# Right {
Width: 20%;
Float: left;
}

</Style>
</Head>
<Body>
<Form ID = "form1" runat = "server">
<Div id = "Container">
<Div id = "Left">
<Asp: Calendar id = "calendar1" runat = "server" Height = "243px" width = "271px"> </ASP: Calendar>
</Div>
<Div id = "right">
<Asp: button id = "button1" runat = "server" text = "OK" postbackurl = "~ /Test/current. aspx "accesskey =" B "backcolor =" # c0ffff "bordercolor =" red "borderwidth =" 1px "/> </div>
</Div>
</Form>
</Body>
</Html>

 

Use the postbackurl attribute of the button to send the selected date of calendar1 on this page to current. aspx, but after using the above Code, no matter how you click the button, the page cannot be switched to current. ASPX page.

 

Sub page_load () sub page_load (byval sender as object, byval e as system. eventargs)
If page. iscrosspagepostback = true then


Dim Cale as calendar
Cale = ctype (previouspage. findcontrol ("calendar1"), calendar)

Label1.text = Cale. selecteddate. tostring
Else
Response. Redirect ("Previous. aspx ")
End if

End sub

If you remove current. in aspx, "If page. the iscrosspagepostback then statement can be switched, but cannot be determined from privious. aspx is coming, so it cannot be omitted. many similar problems are found in Google search, but no root cause is found. In fact, this judgment statement itself has a problem, and the root cause is privious. aspx transfers the value to current. aspx, not current. the iscrosspagepostback attribute of aspx is changed to true, privious. the iscrosspagepostback attribute of aspx is changed to true. Therefore, the judgment statement should be changed

IfPage. previouspage. iscrosspagepostback= True then .....

More details

 

In any case, the previouspage page attribute will contain objects that represent the previous page or the sender page. For example, if page a is sent to page B, the iscrosspagepostback attribute of page A (which can be accessed through the previouspage attribute) is true, and the previouspage attribute of page B has the name of page.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.