p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Professional ASP.NET 4 : in C# and VB (http://p2p.wrox.com/forumdisplay.php?f=554)
-   -   Cross-Page posting not working (http://p2p.wrox.com/showthread.php?t=84228)

Mahesha999 July 2nd, 2011 06:54 AM

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?[:confused:]

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>


Imar July 2nd, 2011 07:55 AM

Hi there,

This code works fine for me. Are both of your pages located in the root of the site? And is JavaScript enabled in your browser?

Imar

Mahesha999 July 2nd, 2011 01:09 PM

Oh!!!! The Author!!!!! (Need more help)
 
Oh!!!! Shocked!!!! The author!!!!

Thanks sir for your help. But still the problem persist.

I learnt many topics in ASP.NET earlier. The problem is that I never keep in touch with them. So I forget.

Javascript is enabled. I tried in all Firefox 4, IE 9 & Crome 10.

The web site directory hierarchy is as shown in the image:
http://img707.imageshack.us/img707/6...ageposting.png

Please help. Thank you.

Imar July 3rd, 2011 06:07 AM

An author yes, but not of this book.... ;-)

Maybe the issue is caused by configuration issues in IIS? From your Solution Explorer it looks like your site is running against IIS. Does it work for you when you try this:

1. In VS2010 choose File | New Web Site (not File | New Project)
2. Create a new C# Web Site
3. Drag Page1 and Pag2 into the new site
4. Hit F5

That works fine for me.

Cheers,

Imar

Mahesha999 July 4th, 2011 05:50 AM

Sir, its still not working

Infact I was doing exactly what you told me (but I created the new web application & the virtual directory under the default web site. (printscreen:http://img231.imageshack.us/img231/8787/locationg.png).)

Earlier, I also tried it by creating the C# web Application:
(File->New->Project->ASP.NET Web Application), instead of (File->New->WebSite). But both ways it did not worked.

I also tried by having my web-site on the file system (by selecting the "File System" in Location dialog). But still hitting button2 postbacks to same page, simply flashing Page1.

Googling whole day. I am not finding any way out. Please help.

Imar July 4th, 2011 06:26 AM

Quote:

Infact I was doing exactly what you told me (but I created the new web application & the virtual directory under the default web site.
A web application is not a web site. So can you please try it again using File | New Web SIte and then chosing the FIle System option? A Web Application uses IIS, which may be causing the issue.

If you have the same issue on a file based web site, the problem may be elsewhere. Maybe you have anti virus software on your machine blocking the functionality?

What do you see when you look at the source of the Page1 in the browser?

Imar

Mahesha999 July 4th, 2011 03:40 PM

No success yet
 
I did exactly in the way asked, i.e. by choosing “File System” in the “Choose Location” dialog box.

Now the application is running under “ASP.NET Development Server” as shown in the notification area of the taskbar.

Also tried by turning off the BitDefender antivirus & firewall. But no success.

Here is the HTML source as can be seen from the Crome
Code:

        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
       
        <html xmlns="http://www.w3.org/1999/xhtml">
        <head><title>
       
        </title></head>
        <body>
        <form method="post" action="Page1.aspx" id="form1">
        <div class="aspNetHidden">
        <input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
        <input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
        <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTE5MzM1MTM2MzMPZBYCAgMPZBYEAgMPPCsACgEADxYCHgJTRBYBBgCAZfEGD84IZGQCCQ8PFgIeBFRleHQFKkhlbGxvIE1haGVzaDxiciAvPkRhdGUgU2VsZWN0ZWQ6IDcvMTMvMjAxMWRkZIHfZ7FDHTHhw+zjjYsG0rjn+JV8AicRXCqaIQ7Vu+Z0" />
        </div>
       
        <script type="text/javascript">
        //<![CDATA[
        var theForm = document.forms['form1'];
        if (!theForm) {
        theForm = document.form1;
        }
        function __doPostBack(eventTarget, eventArgument) {
        if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
        theForm.__EVENTTARGET.value = eventTarget;
        theForm.__EVENTARGUMENT.value = eventArgument;
        theForm.submit();
        }
        }
        //]]>
        </script>
       
       
        <script src="/PostBackUrl/WebResource.axd?d=yXPd-6jqJU9yUpgUop_GXLe959_q_LG_ul4NaiPWx5aj8oORGZE2cl-TVJKxf2ByJM96bXDpnwEuvNuyiPa56bnJZ75zvzulLnpDXuabk481&amp;t=634589204126647261" type="text/javascript"></script>

       
        <div class="aspNetHidden">
       
        <input type="hidden" name="__PREVIOUSPAGE" id="__PREVIOUSPAGE" value="5K-qVQ5ErNPEBHVtoLZPE8bOGk2SM7-_0f9twN6s0W12WUFhwjQbnZrdV_8Jr6VTOV1msVJoSYWliMenalsDM14-Kj2BYUKKxdgbK4VO3qg1" />
        <input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWMAKD0PzVCALs0bLrBgLcrveCCgKwxN67DgLZ9+GJDQLZ992kBgLZ98nfDwLZ96V7Atn30cMFAtn3zf4OApaUjIgLApaU+KMMApaU1N4FApaUwPkOApaUvJUGApaUqLAPApaUhGsClpTwhggClpSs7w4ClpSYigYC8a2qkwEC8a2GzgoC8a3y6QMC8a3uhAsC8a3avwwC8a222wUC8a2i9g4C8a2ekQYC8a3K+QQC8a2mlQwC7LrIvQ8C7LqkWQLsupD0CQLsuoyvAQLsuvjKCgLsutTlAwLsusCACwLsury8DALsuuiEAQLsusS/CgLH09fIBQLH08PjDgLH07+fBgLH06u6DwLH04dVAsfT8/AJAoznisYGArursYYI+k7s8PddlfZL/XTTLWRLi8jsbr3GEAm31z5OzdWc/2c=" />
        </div>
        Enter your name:<br />
        <input name="TextBox1" type="text" value="Mahesh" id="TextBox1" />
        <p>
        When do you want to fly?<br />
        <table id="Calendar1" cellspacing="0" cellpadding="2" title="Calendar" style="border-width:1px;border-style:solid;border-collapse:collapse;">
        <tr><td colspan="7" style="background-color:Silver;"><table cellspacing="0" style="width:100%;border-collapse:collapse;">
        <tr><td style="width:15%;"><a href="javascript:__doPostBack('Calendar1','V4169')" style="color:Black" title="Go to the previous month">&lt;</a></td><td align="center" style="width:70%;">July 2011</td><td align="right" style="width:15%;"><a href="javascript:__doPostBack('Calendar1','V4230')" style="color:Black" title="Go to the next month">&gt;</a></td></tr>
        </table></td></tr><tr><th align="center" abbr="Sunday" scope="col">Sun</th><th align="center" abbr="Monday" scope="col">Mon</th><th align="center" abbr="Tuesday" scope="col">Tue</th><th align="center" abbr="Wednesday" scope="col">Wed</th><th align="center" abbr="Thursday" scope="col">Thu</th><th align="center" abbr="Friday" scope="col">Fri</th><th align="center" abbr="Saturday" scope="col">Sat</th></tr><tr><td align="center" style="width:14%;"><a href="javascript:__doPostBack('Calendar1','4194')" style="color:Black" title="June 26">26</a></td><td align="center" style="width:14%;"><a href="javascript:__doPostBack('Calendar1','4195')" style="color:Black" title="June 27">27</a></td><td align="center" style="width:14%;"><a href="javascript:__doPostBack('Calendar1','4196')" style="color:Black" title="June 28">28</a></td><td align="center" style="width:14%;"><a href="javascript:__doPostBack('Calendar1','4197')" style="color:Black" title="June 29">29</a></td><td align="center" style="width:14%;"><a href="javascript:__doPostBack('Calendar1','4198')" style="color:Black" title="June 30">30</a></td><td align="center" style="width:14%;"><a href="javascript:__doPostBack('Calendar1','4199')" style="color:Black" title="July 01">1</a></td><td align="center" style="width:14%;"><a href="javascript:__doPostBack('Calendar1','4200')" style="color:Black" title="July 02">2</a></td></tr><tr><td align="center" style="width:14%;"><a href="javascript:__doPostBack('Calendar1','4201')" style="color:Black" title="July 03">3</a></td><td align="center" style="width:14%;"><a href="javascript:__doPostBack('Calendar1','4202')" style="color:Black" title="July 04">4</a></td><td align="center" style="width:14%;"><a href="javascript:__doPostBack('Calendar1','4203')" style="color:Black" title="July 05">5</a></td><td align="center" style="width:14%;"><a href="javascript:__doPostBack('Calendar1','4204')" style="color:Black" title="July 06">6</a></td><td align="center" style="width:14%;"><a href="javascript:__doPostBack('Calendar1','4205')" style="color:Black" title="July 07">7</a></td><td align="center" style="width:14%;"><a href="javascript:__doPostBack('Calendar1','4206')" style="color:Black" title="July 08">8</a></td><td align="center" style="width:14%;"><a href="javascript:__doPostBack('Calendar1','4207')" style="color:Black" title="July 09">9</a></td></tr><tr><td align="center" style="width:14%;"><a href="javascript:__doPostBack('Calendar1','4208')" style="color:Black" title="July 10">10</a></td><td align="center" style="width:14%;"><a href="javascript:__doPostBack('Calendar1','4209')" style="color:Black" title="July 11">11</a></td><td align="center" style="width:14%;"><a href="javascript:__doPostBack('Calendar1','4210')" style="color:Black" title="July 12">12</a></td><td align="center" style="color:White;background-color:Silver;width:14%;"><a href="javascript:__doPostBack('Calendar1','4211')" style="color:White" title="July 13">13</a></td><td align="center" style="width:14%;"><a href="javascript:__doPostBack('Calendar1','4212')" style="color:Black" title="July 14">14</a></td><td align="center" style="width:14%;"><a href="javascript:__doPostBack('Calendar1','4213')" style="color:Black" title="July 15">15</a></td><td align="center" style="width:14%;"><a href="javascript:__doPostBack('Calendar1','4214')" style="color:Black" title="July 16">16</a></td></tr><tr><td align="center" style="width:14%;"><a href="javascript:__doPostBack('Calendar1','4215')" style="color:Black" title="July 17">17</a></td><td align="center" style="width:14%;"><a href="javascript:__doPostBack('Calendar1','4216')" style="color:Black" title="July 18">18</a></td><td align="center" style="width:14%;"><a href="javascript:__doPostBack('Calendar1','4217')" style="color:Black" title="July 19">19</a></td><td align="center" style="width:14%;"><a href="javascript:__doPostBack('Calendar1','4218')" style="color:Black" title="July 20">20</a></td><td align="center" style="width:14%;"><a href="javascript:__doPostBack('Calendar1','4219')" style="color:Black" title="July 21">21</a></td><td align="center" style="width:14%;"><a href="javascript:__doPostBack('Calendar1','4220')" style="color:Black" title="July 22">22</a></td><td align="center" style="width:14%;"><a href="javascript:__doPostBack('Calendar1','4221')" style="color:Black" title="July 23">23</a></td></tr><tr><td align="center" style="width:14%;"><a href="javascript:__doPostBack('Calendar1','4222')" style="color:Black" title="July 24">24</a></td><td align="center" style="width:14%;"><a href="javascript:__doPostBack('Calendar1','4223')" style="color:Black" title="July 25">25</a></td><td align="center" style="width:14%;"><a href="javascript:__doPostBack('Calendar1','4224')" style="color:Black" title="July 26">26</a></td><td align="center" style="width:14%;"><a href="javascript:__doPostBack('Calendar1','4225')" style="color:Black" title="July 27">27</a></td><td align="center" style="width:14%;"><a href="javascript:__doPostBack('Calendar1','4226')" style="color:Black" title="July 28">28</a></td><td align="center" style="width:14%;"><a href="javascript:__doPostBack('Calendar1','4227')" style="color:Black" title="July 29">29</a></td><td align="center" style="width:14%;"><a href="javascript:__doPostBack('Calendar1','4228')" style="color:Black" title="July 30">30</a></td></tr><tr><td align="center" style="width:14%;"><a href="javascript:__doPostBack('Calendar1','4229')" style="color:Black" title="July 31">31</a></td><td align="center" style="width:14%;"><a href="javascript:__doPostBack('Calendar1','4230')" style="color:Black" title="August 01">1</a></td><td align="center" style="width:14%;"><a href="javascript:__doPostBack('Calendar1','4231')" style="color:Black" title="August 02">2</a></td><td align="center" style="width:14%;"><a href="javascript:__doPostBack('Calendar1','4232')" style="color:Black" title="August 03">3</a></td><td align="center" style="width:14%;"><a href="javascript:__doPostBack('Calendar1','4233')" style="color:Black" title="August 04">4</a></td><td align="center" style="width:14%;"><a href="javascript:__doPostBack('Calendar1','4234')" style="color:Black" title="August 05">5</a></td><td align="center" style="width:14%;"><a href="javascript:__doPostBack('Calendar1','4235')" style="color:Black" title="August 06">6</a></td></tr>
        </table></p>
        <br />
        <input type="submit" name="Button1" value="Submit page to itself" id="Button1" />
        <input type="submit" name="Button2" value="Submit page to Page2.aspx" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;Button2&quot;, &quot;&quot;, false, &quot;&quot;, &quot;Page2.aspx&quot;, false, false))" id="Button2" />
        <p>
        <span id="Label1">Hello Mahesh<br />Date Selected: 7/13/2011</span></p>
        </form>
        </body>
        </html>


Imar July 4th, 2011 04:06 PM

I compared your code with mine, and besides the few obvious differences, I see no reason why this shouldn't work.

Final two things to check before I am out of ideas:

1. Make sure JavaScript is enabled by writing some simple JavaScript code in the page.

2. Request the axd file directly and see if that shows something. E.g. make a request for something like http://localhost:1234/PostBackUrl/We...89204126647261

Make sure you use your own port number and exact URL (which you can find by looking at the source in the browser).

Other than that, I am out of ideas. Did you search Google for people with similar problems?

Imar

Mahesha999 July 5th, 2011 03:25 AM

JavaScript is working
This is the modified Page1.aspx to include an additional button that runs the JavaScript

Code:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Page1.aspx.cs" Inherits="Page1" %>

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

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script language="javascript" type="text/javascript">
// <![CDATA[

        function Button3_onclick() {
            //http://img715.imageshack.us/img715/7631/javascriptisactive.png
            alert("This is to test if the JavaScript works or not.");
        }

// ]]>
    </script>
</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" />
            <input id="Button3" type="button" value="Run JavaScript" onclick="return Button3_onclick()" />
        <p>
        <asp:Label ID="Label1" Runat="server"></asp:Label></p>
    </form>
</body>
</html>

Output Printscreen: http://img715.imageshack.us/img715/7...ptisactive.png

In the browser's html source window, the axd file's url seems something like this:

Code:

<script src="/PostBackUrl/WebResource.axd?d=yXPd-6jqJU9yUpgUop_GXLe959_q_LG_ul4NaiPWx5aj8oORGZE2cl-TVJKxf2ByJM96bXDpnwEuvNuyiPa56bnJZ75zvzulLnpDXuabk481&amp;t=634589204126647261" type="text/javascript"></script>
But when tried to request the file directly, following error occured:http://img841.imageshack.us/img841/9939/axderror.png

I googled for the same.
many people had this problem (about the postback, not specific to the axd file), they found different solutions that did not worked for me.

merk (third post) talked about the axd file problem at http://forums.asp.net/t/1052857.aspx/1. But did not explained how solved it to the length:

Imar July 5th, 2011 08:37 AM

That at least explains why the postback doesn't work.

Not sure why the files turn up as 404's. Could be an issue with IIS or the ASP.NET framework.

You could try repairing ASP.NET, or try this Google search.

Other than that, I am really out of ideas now..

Imar


All times are GMT -4. The time now is 10:05 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.