TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Tangara G
NA
298
94k
What is wrong with my cross page post back ?
Dec 26 2016 4:48 AM
Hi,
I tried out this cross page post back to understand the concept but it doesn't give me anything on the 2nd page. Hope someone can tell me what went wrong with my code. Tks.
<%@ Page Language=
"C#"
AutoEventWireup=
"true"
CodeBehind=
"WebForm1.aspx.cs"
Inherits=
"hiddenfieldtest.WebForm1"
%>
<!DOCTYPE html>
<html xmlns=
"http://www.w3.org/1999/xhtml"
>
<head runat=
"server"
>
<title>Cross Page Postback Example in asp.net</title>
</head>
<body>
<form id=
"form1"
runat=
"server"
>
<div>
<table>
<tr>
<td><b>Enter UserName:</b></td>
<td><asp:TextBox ID=
"txtUserName"
runat=
"server"
/></td>
</tr>
<tr>
<td><b>Enter Location:</b></td>
<td><asp:TextBox ID=
"txtLocation"
runat=
"server"
/></td>
</tr>
<tr>
<td></td>
<td><asp:Button ID=
"btnPostback"
Text=
"Postback"
runat=
"server"
PostBackUrl=
"~/WebForm2.aspx"
/> </td>
</tr>
</table>
</div>
</form>
</body>
</html>
<%@ Page Language=
"C#"
AutoEventWireup=
"true"
CodeBehind=
"WebForm2.aspx.cs"
Inherits=
"hiddenfieldtest.WebForm2"
%>
<!DOCTYPE html>
<html xmlns=
"http://www.w3.org/1999/xhtml"
>
<head runat=
"server"
>
<title></title>
</head>
<body>
<form id=
"form1"
runat=
"server"
>
<div>
<b><u>WebForm2.aspx Page</u></b><br /><br />
<label id=
"lblName"
runat=
"server"
/><br /><br />
<label id=
"lblLocation"
runat=
"server"
/>
</div>
</form>
</body>
</html>
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
System.Web.UI;
using
System.Web.UI.WebControls;
namespace
hiddenfieldtest
{
public
partial
class
WebForm2 : System.Web.UI.Page
{
protected
void
Page_Load(object sender, EventArgs e)
{
if
(PreviousPage != null && PreviousPage.IsCrossPagePostBack)
{
TextBox txtName = (TextBox)PreviousPage.FindControl(
"txtUserName"
);
TextBox txtLocation = (TextBox)PreviousPage.FindControl(
"txtLocation"
);
lblName.InnerText =
"Welcome to WebForm2.aspx page "
+ txtName.Text;
lblLocation.InnerText =
"Your Location: "
+ txtLocation.Text;
}
else
{
Response.Redirect(
"WebForm1.aspx"
);
}
}
}
}
Reply
Answers (
9
)
Enable ipv6 on windows server
Filtering Records in Grid Using MVC