Cross-Page PostBack in asp.net

Posted by Thiru under ASP.NET on 9/16/2011 | Points: 10 | Views : 3197 | Status : [Member] | Replies : 6
Hi,
I try to use cross-page postback - its not working can you find where i made the mistake?

Page One: adultreg.aspx
Created simple registration form:
<asp:TextBox ID="txtfnm" runat="server" CssClass="txtbox" Text="sen">
<asp:TextBox ID="txtlnm" runat="server" CssClass="txtbox" Text="web">


on submit button:
stored in database and
Response.Redirect("regconfirmation.aspx")


Page Two: regconfirm.aspx
Design:
<%@ PreviousPageType VirtualPath="~/adultreg.aspx" %>
<asp:Label ID="lblname" runat="server" Text=""></asp:Label>


Code:
Public Partial Class WebForm6
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
lblname.Text = "Hi "
If Not Page.PreviousPage Is Nothing Then
Dim sourcetextbox As TextBox
sourcetextbox = CType(PreviousPage.FindControl("txtfnm"), TextBox)
If Not sourcetextbox Is Nothing Then
lblname.Text = lblname.Text & UCase(sourcetextbox.Text)
End If
End If

If Not Page.PreviousPage Is Nothing Then
Dim srctextbox As TextBox
srctextbox = CType(PreviousPage.FindControl("txtlnm"), TextBox)
If Not srctextbox Is Nothing Then
lblname.Text = lblname.Text & " " & UCase(srctextbox.Text)
End If
End If

lblname.Text = lblname.Text & " , your signup is completed successfully." & vbLf & "We will get back to you shortly." & vbLf & "Thanks for registering with us."

End Sub

End Class


Result shows:
Hi , your signup is completed successfully. We will get back to you shortly. Thanks for registering with us.

Expected Result:
Hi , SEN WEB your signup is completed successfully. We will get back to you shortly. Thanks for registering with us.

Where i made the mistake ?




Responses

Posted by: Seenuvasan on: 9/16/2011 [Member] Starter | Points: 25

Up
0
Down
Hi thiru,

i think , you need to enable " cross page post back" option for submit button on registration page.

follow below steps to enable:
- go to submit button properties.and select "postBackUrl" then pick regconfirmation.aspx url.

now run the app and see the result

Thanks,
Seen

Thiru, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Prabhakar on: 9/16/2011 [Member] [MVP] Starter | Points: 25

Up
0
Down
Hi thiru,

try this for Redirect . .

Response.Redirect("~/regconfirmation.aspx")


Best Regard's
Prabhakar

Thiru, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Thiru on: 9/16/2011 [Member] Starter | Points: 25

Up
0
Down
Hi both,
I did as suggested by seenuvasan as well as prabhakar

now i am getting error here: Response.Redirect("~/regconfirmation.aspx")

Exception:

ex = {Property evaluation failed.}


Thiru, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Prabhakar on: 9/16/2011 [Member] [MVP] Starter | Points: 25

Up
0
Down
Thiru


try this ..


Response.Redirect ("regconfirmation.aspx", false);


Best Regard's
Prabhakar

Thiru, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Thiru on: 9/16/2011 [Member] Starter | Points: 25

Up
0
Down
Hi Prabhakar,
Now its i didn't get any exception.
i used a pointbreak and f8

Its not getting any control from page one

i mean: this line returns nothing :
 sourcetextbox = CType(PreviousPage.FindControl("txtfnm"), TextBox) 


The code i used here is mentioned above - is there any thing i missed?
Why its returning NOTHING?



Thiru, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Seenuvasan on: 9/16/2011 [Member] Starter | Points: 25

Up
0
Down
Hi,

look on below sample code. i don't know vb. so written in c#.
in reg page
create property like below.
pulic string Lname
{
get{return txtfnm.Text;}
}

in regconfirmation.aspx page
if(Page.PreviousPage !=null && Page.PreviousPage==true)
{
adultreg obj=(adultreg)Page.PreviousPage;
lblname.Text=obj.Lname;
}

Try like this


Thanks,
Seen

Thiru, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response