View Single Post
  #1 (permalink)  
Old July 2nd, 2011, 06:54 AM
Mahesha999 Mahesha999 is offline
Authorized User
Points: 51, Level: 1
Points: 51, Level: 1 Points: 51, Level: 1 Points: 51, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2011
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Exclamation Cross-Page posting not working

I am doing the cross-page posting topic from the book.

I copied the whole code from Listings 1-9 & 1-10 in the corresponding web forms Page1.aspx & Page2.aspx

And then run the web app.

Page1 was shown. I entered name & selected the date.
Then clicked "Submit page to itself" button. It is giving responce as expected.

But when I click "Submit page to Page2.aspx" button, the page simple flashes up again showing Page1, even not refreshing its field & the previous responce.

Whats wrong?

Please guide!!!

Tried many times. But no success.

I stuck over here.

Waiting for your help. Thank you!!!!

Code:
Page1.aspx
Code:
<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
    protected void Button1_Click(object sender, System.EventArgs e)
    {
        Label1.Text = "Hello " + TextBox1.Text + "<br />" +
        "Date Selected: " + Calendar1.SelectedDate.ToShortDateString();
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        Enter your name:<br />
        <asp:Textbox ID="TextBox1" Runat="server"></asp:Textbox>
        <p>
            When do you want to fly?<br />
            <asp:Calendar ID="Calendar1" Runat="server"></asp:Calendar></p>
            <br />
            <asp:Button ID="Button1" Runat="server" Text="Submit page to itself" OnClick="Button1_Click" />
            <asp:Button ID="Button2" Runat="server" Text="Submit page to Page2.aspx" PostBackUrl="~/Page2.aspx" />
        <p>
        <asp:Label ID="Label1" Runat="server"></asp:Label></p>
    </form>
</body>
</html>
Page2.aspx
Code:
<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
    protected void Page_Load(object sender, System.EventArgs e)
    {
        TextBox pp_Textbox1;
        Calendar pp_Calendar1;
        pp_Textbox1 = (TextBox)PreviousPage.FindControl("Textbox1");
        pp_Calendar1 = (Calendar)PreviousPage.FindControl("Calendar1");
        Label1.Text = "Hello " + pp_Textbox1.Text + "<br />" + "Date Selected: " +
        pp_Calendar1.SelectedDate.ToShortDateString();
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <asp:Label ID="Label1" Runat="server"></asp:Label>
    </form>
</body>
</html>

Last edited by Mahesha999; July 2nd, 2011 at 06:56 AM.. Reason: Adding code