At times there becomes a need to transfer data from one page to another page in ASP.NET and for doing this, there are various ways through which we can transfer data from one page to another page. For transferring the data we need to store the data either on the client side or on the server side.
Client Side Storage Mechanism:-
Client Side Storage Mechanism:-
- Cookies
- Query String
- Hidden Field (View State)
- Cache
Server Side Storage Mechanism:-
- Session
- Application
We can easily transfer data through a query string but the drawback of using this concept is that the string is visible in the address bar and your site can be easily hacked. This means we cannot transfer sensitive data such as passwords or any other data. And the 2nd limitation is that we can transfer data maximum up to 255 characters and not more than that.
There is one more approach that can be used for transferring data that is the PostBackUrl property. This property can be set on a Button when you need to transfer data from one page to another page. The value of this property should be the transferred page. Let's suppose that we have 2 pages
There is one more approach that can be used for transferring data that is the PostBackUrl property. This property can be set on a Button when you need to transfer data from one page to another page. The value of this property should be the transferred page. Let's suppose that we have 2 pages
- Survey.aspx
- SurveyReceipt.aspx
And we need to transfer data from survey.aspx to surveyReceipt.aspx. In this case we set the PostBackUrl of the button control on survey.aspx to SurveyReceipt.aspx.
Following is the design of Survey.aspx
Following is the design of Survey.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Survey.aspx.cs" Inherits="_Default" %>
<!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>Untitled Page</title>
<style type="text/css">
.style1
{
height: 46px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<table style="width: 100%; color: #0E0E6C">
<tr>
<td align="left" valign="top" colspan="2" style="background-color: Maroon; color: White;">
<span style="font-size: 18pt; font-family: Verdana; font-style: normal;"> Help
us to help you!</span>
<br />
Personal Info
</td>
</tr>
<tr>
<td align="right" valign="top">
Name:</td>
<td>
<input id="txtName" type="text" name="txtName" runat="server" enableviewstate="true" />
</td>
</tr>
<tr>
<td align="right" valign="top" class="style1">
Gender:</td>
<td class="style1">
<input id="Radio1" name="optGender" type="radio" value="Female" runat="server" enableviewstate="true" />Female
<br />
<input id="Radio2" name="optGender" type="radio" value="Male" runat="server" enableviewstate="true" />Male
</td>
</tr>
<tr>
<td align="right" valign="top">
Mountain Bike Rider?</td>
<td>
<input id="chkMBR" checked="checked" name="chkMBR" type="checkbox" runat="server"
enableviewstate="true" />
</td>
</tr>
<tr>
<td align="right" valign="top">
Road Rider?</td>
<td>
<input id="chkRR" checked="checked" name="chkRR" type="checkbox" runat="server" enableviewstate="true" />
</td>
</tr>
<tr>
<td align="right" valign="top">
Favorite Trails from <br />
around the world:</td>
<td>
<textarea id="txtTrails" cols="50" name="txtTrails" rows="3" runat="server" enableviewstate="true"></textarea>
</td>
</tr>
</table>
<hr />
<asp:Table ID="tblOuter" runat="server" ForeColor="#0E0E6C" Width="100%">
<asp:TableRow ID="outerR1" runat="server">
<asp:TableCell ID="outerR1C1" runat="server" ColumnSpan="2">
<asp:Panel ID="pnlActivity" runat="server" Width="100px">
Recent and Planned Activity</asp:Panel>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow ID="outerR2" runat="server">
<asp:TableCell ID="outerR2C1" runat="server" VerticalAlign="Middle" Width="1%" Wrap="False">Rides</asp:TableCell>
<asp:TableCell ID="outerR2C2" runat="server">
<asp:Table ID="tblInner" runat="server" GridLines="None" Width="100%">
<asp:TableRow ID="innerR1" runat="server">
<asp:TableCell ID="innerR1C1" runat="server" Wrap="false" Width="1%">
<asp:Literal ID="itlLast" runat="server" Text="Last Trip>>>"></asp:Literal>
</asp:TableCell>
<asp:TableCell ID="innerR1C2" runat="server">
<asp:Calendar ID="calLast" runat="server" TodayDayStyle-BackColor="Maroon"></asp:Calendar>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow ID="innerR2" runat="server">
<asp:TableCell ID="innerR2C1" runat="server" Wrap="false" Width="1%">
<asp:Literal ID="ltlNext" runat="server" Text="Next Trip>>>"></asp:Literal>
</asp:TableCell>
<asp:TableCell ID="innerR2C2" runat="server">
<asp:Calendar ID="calNext" runat="server" TodayDayStyle-BackColor="Maroon"></asp:Calendar>|
</asp:TableCell>
</asp:TableRow>
</asp:Table>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow ID="outerR3" runat="server">
<asp:TableCell ID="outerR3C1" runat="server" HorizontalAlign="Left" VerticalAlign="Top"
Width="1%" Wrap="False">Your Ability:</asp:TableCell>
<asp:TableCell ID="outerR3C2" runat="server">
<asp:DropDownList ID="ddAbility" runat="server">
<asp:ListItem Text="Beginner"></asp:ListItem>
<asp:ListItem Text="Competent"></asp:ListItem>
<asp:ListItem Text="Expert"></asp:ListItem>
</asp:DropDownList>
<!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>Untitled Page</title>
<style type="text/css">
.style1
{
height: 46px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<table style="width: 100%; color: #0E0E6C">
<tr>
<td align="left" valign="top" colspan="2" style="background-color: Maroon; color: White;">
<span style="font-size: 18pt; font-family: Verdana; font-style: normal;"> Help
us to help you!</span>
<br />
Personal Info
</td>
</tr>
<tr>
<td align="right" valign="top">
Name:</td>
<td>
<input id="txtName" type="text" name="txtName" runat="server" enableviewstate="true" />
</td>
</tr>
<tr>
<td align="right" valign="top" class="style1">
Gender:</td>
<td class="style1">
<input id="Radio1" name="optGender" type="radio" value="Female" runat="server" enableviewstate="true" />Female
<br />
<input id="Radio2" name="optGender" type="radio" value="Male" runat="server" enableviewstate="true" />Male
</td>
</tr>
<tr>
<td align="right" valign="top">
Mountain Bike Rider?</td>
<td>
<input id="chkMBR" checked="checked" name="chkMBR" type="checkbox" runat="server"
enableviewstate="true" />
</td>
</tr>
<tr>
<td align="right" valign="top">
Road Rider?</td>
<td>
<input id="chkRR" checked="checked" name="chkRR" type="checkbox" runat="server" enableviewstate="true" />
</td>
</tr>
<tr>
<td align="right" valign="top">
Favorite Trails from <br />
around the world:</td>
<td>
<textarea id="txtTrails" cols="50" name="txtTrails" rows="3" runat="server" enableviewstate="true"></textarea>
</td>
</tr>
</table>
<hr />
<asp:Table ID="tblOuter" runat="server" ForeColor="#0E0E6C" Width="100%">
<asp:TableRow ID="outerR1" runat="server">
<asp:TableCell ID="outerR1C1" runat="server" ColumnSpan="2">
<asp:Panel ID="pnlActivity" runat="server" Width="100px">
Recent and Planned Activity</asp:Panel>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow ID="outerR2" runat="server">
<asp:TableCell ID="outerR2C1" runat="server" VerticalAlign="Middle" Width="1%" Wrap="False">Rides</asp:TableCell>
<asp:TableCell ID="outerR2C2" runat="server">
<asp:Table ID="tblInner" runat="server" GridLines="None" Width="100%">
<asp:TableRow ID="innerR1" runat="server">
<asp:TableCell ID="innerR1C1" runat="server" Wrap="false" Width="1%">
<asp:Literal ID="itlLast" runat="server" Text="Last Trip>>>"></asp:Literal>
</asp:TableCell>
<asp:TableCell ID="innerR1C2" runat="server">
<asp:Calendar ID="calLast" runat="server" TodayDayStyle-BackColor="Maroon"></asp:Calendar>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow ID="innerR2" runat="server">
<asp:TableCell ID="innerR2C1" runat="server" Wrap="false" Width="1%">
<asp:Literal ID="ltlNext" runat="server" Text="Next Trip>>>"></asp:Literal>
</asp:TableCell>
<asp:TableCell ID="innerR2C2" runat="server">
<asp:Calendar ID="calNext" runat="server" TodayDayStyle-BackColor="Maroon"></asp:Calendar>|
</asp:TableCell>
</asp:TableRow>
</asp:Table>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow ID="outerR3" runat="server">
<asp:TableCell ID="outerR3C1" runat="server" HorizontalAlign="Left" VerticalAlign="Top"
Width="1%" Wrap="False">Your Ability:</asp:TableCell>
<asp:TableCell ID="outerR3C2" runat="server">
<asp:DropDownList ID="ddAbility" runat="server">
<asp:ListItem Text="Beginner"></asp:ListItem>
<asp:ListItem Text="Competent"></asp:ListItem>
<asp:ListItem Text="Expert"></asp:ListItem>
</asp:DropDownList>
No comments:
Post a Comment