This article I will show you how you can pass multiple
parameters in querystring or url in asp.net using c#.net.
Some of my previous articles are as follows: Validate
DropDownlist Using RegularExpression In Asp.Net, Confirmation
Message With Yes, No Button In Asp.Net Using ConfirmButtonExtender and
ModalPopupExtender, Dynamically
Add TextBox Control and Detect TextBox Value in Asp.Net Using C#, Call
C# Code or Function or Method From Javascript In Asp.Net, Get
All Checked Checkbox Value Using jQuery in Asp.Net CheckBoxList, Ajax
Call Using UpdatePanel Display Data On Button Click Without Refresh In Asp.Net,
C#, Comment
System OR Form and Display In GridView Using C# In Asp.Net.
So for this article first we will create a new asp.net application and add a button control. Now generate the button click event and add the below code.
So for this article first we will create a new asp.net application and add a button control. Now generate the button click event and add the below code.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm9.aspx.cs" Inherits="WebApplication2.WebForm9"
%>
<!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>Asp.Net
Pass Multiple Parameters in QueryString or URL in Asp.Net Using C#.Net</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Text="Submit" onclick="Button1_Click" />
</div>
</form>
</body>
</html>
|
Now add the .cs code.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication2
{
public partial class WebForm9 : System.Web.UI.Page
{
protected
void Page_Load(object
sender, EventArgs e)
{
}
protected
void Button1_Click(object
sender, EventArgs e)
{
Response.Redirect("WebForm10.aspx?FirstName=John&LastName=Mathu&Rank=20");
}
}
}
|
In above code I have passed the request querystring value in url.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication2
{
public partial class WebForm9 : System.Web.UI.Page
{
protected
void Page_Load(object
sender, EventArgs e)
{
}
protected
void Button1_Click(object
sender, EventArgs e)
{
Response.Redirect("WebForm10.aspx?FirstName=John&LastName=Mathu&Rank=20");
}
}
}
|
Now on other page add the add the below code to retrieve the
value passed in url.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm10.aspx.cs" Inherits="WebApplication2.WebForm10"
%>
<!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>Result</title>
</head>
<body>
<form id="form1" runat="server">
<div>
First Name : <asp:Label ID="lblFname" runat="server" Text="Label"></asp:Label><br />
Last Name :<asp:Label ID="lblLname" runat="server" Text="Label"></asp:Label><br />
Rank :<asp:Label ID="lblRank" runat="server" Text="Label"></asp:Label><br />
</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 WebApplication2
{
public partial class WebForm10 : System.Web.UI.Page
{
protected
void Page_Load(object
sender, EventArgs e)
{
//FirstName=John&LastName=Mathu&Rank=20
if
(Request.QueryString["FirstName"]
!= null)
{
lblFname.Text =
Request.QueryString["FirstName"].ToString();
}
if
(Request.QueryString["LastName"]
!= null)
{
lblLname.Text =
Request.QueryString["LastName"].ToString();
}
if
(Request.QueryString["Rank"] != null)
{
lblRank.Text =
Request.QueryString["Rank"].ToString();
}
}
}
}
|
In above code I have checked the url value and display into
the page. Now we have done run the application to check the output.
Now click on button. As we click on button break pint will
hit and we will get the value.
0 comments:
Please let me know your view