Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Jun 30, 2010 06:59 PM by fanette48
Member
64 Points
639 Posts
Feb 07, 2007 04:39 AM|LINK
I would like to get parameter of ASP.NET script in URL example : /localhost/example.asp?parameter1 How can i to get this parameter ?
can you give me a example? ( using C#)
Thanks a lot
JC
asp.net.c#
All-Star
29674 Points
5334 Posts
MVP
Feb 07, 2007 04:47 AM|LINK
To get a querystring you can use the Request.Querystring property:
Request.Querystring("parameter1")
Participant
917 Points
225 Posts
Feb 07, 2007 05:13 AM|LINK
Actually in C# it would be:
//this takes request parameters only from the query string Request.QueryString["parameter1"]; //this one works for bot - form and query string Request["parameter1"];
19530 Points
3894 Posts
Feb 07, 2007 05:17 AM|LINK
In Page1.aspx
Response.Redirect("Page2.aspx?param1=Test");
In Page2.aspx
if (Request.QueryString["param1"] != null) Response.Write("From Page1 param1 value=" + Request.QueryString["param1"]);
Thanks
Feb 07, 2007 05:23 AM|LINK
lol, sometime by sitting with a VB.Net project at the moment can destroy the way of writing C#, or the syntax can in a hurry be written wrong ;)
To add something vaulable to this post, you can also use Request.Params["parameter1"]
925 Points
254 Posts
Feb 07, 2007 05:30 AM|LINK
In the first page
response.redirect("a.aspx?ids=1&val=100",true)
and in the second page that is a.aspx
a=Request.QueryString("ids")
b= Request.QueryString("val")
Feb 07, 2007 05:36 AM|LINK
thanks for you all
I'm sorry... but I still can't understand...
how about this example of url : http://forums.asp.net/AddPost.aspx?PostID=1566979
I want to get "1566979"
is it correct →Request.Querystring("PostID") and I can get 1566979
once I get postID (1566969) I'll replace the X as 1566979
string strConn = "data Source=x.x.x.x;user=sa;password=1234;initial catalog=Member"; string strSQL = "select Subject,nContent from pro_News where Member_no = "x" "; SqlConnection conn = new SqlConnection(strConn); SqlCommand cmd = new SqlCommand(strSQL,conn); cmd.CommandType = CommandType.Text; conn.Open(); SqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { Label1.Text= (dr["Name"].ToString()); Label2.Text = (dr["Address"].ToString()); } cmd.Dispose(); conn.Close(); conn.Dispose();
Feb 07, 2007 05:52 AM|LINK
the first page is writted with VB by other people ( I can't modify it..)
if I did
then I can get a=18 , b=100 is it correct??
37421 Points
5632 Posts
Feb 07, 2007 06:11 AM|LINK
if you have this link below
a = 1
b = 100
HC
Feb 07, 2007 06:38 AM|LINK
hi, how do I know which should I put it in response.redirect( )?
I have 2 page now ( a is writted by VB .. I can't modify it.. , b is writted by C#)
page a is shows many title... and once user click one of them it will direct to page b. page b will shows content which user click from page a..
so that's why I'm wondering .. is it ok? get parameter in url when we are in page b...
jcjcjc
Member
64 Points
639 Posts
How to get parameter in url ( by C# for .net)
Feb 07, 2007 04:39 AM|LINK
I would like to get parameter of ASP.NET script in URL
example : /localhost/example.asp?parameter1
How can i to get this parameter ?
can you give me a example? ( using C#)
Thanks a lot
JC
asp.net.c#
Fredrik N
All-Star
29674 Points
5334 Posts
MVP
Re: How to get parameter in url ( by C# for .net)
Feb 07, 2007 04:47 AM|LINK
To get a querystring you can use the Request.Querystring property:
Request.Querystring("parameter1")
MVP, ASPInsider, WCF RIA Services Insider
My Blog
fafar
Participant
917 Points
225 Posts
Re: How to get parameter in url ( by C# for .net)
Feb 07, 2007 05:13 AM|LINK
Actually in C# it would be:
Aure Entuluva!
- Day shall come again!
e_screw
All-Star
19530 Points
3894 Posts
Re: How to get parameter in url ( by C# for .net)
Feb 07, 2007 05:17 AM|LINK
In Page1.aspx
Response.Redirect("Page2.aspx?param1=Test");
In Page2.aspx
if (Request.QueryString["param1"] != null)
Response.Write("From Page1 param1 value=" + Request.QueryString["param1"]);
Thanks
Electronic Screw
Website||Blog||Dub@i.net
Fredrik N
All-Star
29674 Points
5334 Posts
MVP
Re: How to get parameter in url ( by C# for .net)
Feb 07, 2007 05:23 AM|LINK
lol, sometime by sitting with a VB.Net project at the moment can destroy the way of writing C#, or the syntax can in a hurry be written wrong ;)
To add something vaulable to this post, you can also use Request.Params["parameter1"]
MVP, ASPInsider, WCF RIA Services Insider
My Blog
sreejith77
Participant
925 Points
254 Posts
Re: How to get parameter in url ( by C# for .net)
Feb 07, 2007 05:30 AM|LINK
In the first page
response.redirect("a.aspx?ids=1&val=100",true)
and in the second page that is a.aspx
a=Request.QueryString("ids")
b= Request.QueryString("val")
http://tips4dotnet.blogspot.com/
jcjcjc
Member
64 Points
639 Posts
Re: How to get parameter in url ( by C# for .net)
Feb 07, 2007 05:36 AM|LINK
thanks for you all
I'm sorry... but I still can't understand...
how about this example of url : http://forums.asp.net/AddPost.aspx?PostID=1566979
I want to get "1566979"
is it correct →Request.Querystring("PostID") and I can get 1566979
once I get postID (1566969) I'll replace the X as 1566979
string strConn = "data Source=x.x.x.x;user=sa;password=1234;initial catalog=Member";
string strSQL = "select Subject,nContent from pro_News where Member_no = "x" ";
SqlConnection conn = new SqlConnection(strConn);
SqlCommand cmd = new SqlCommand(strSQL,conn);
cmd.CommandType = CommandType.Text;
conn.Open();
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
Label1.Text= (dr["Name"].ToString());
Label2.Text = (dr["Address"].ToString());
}
cmd.Dispose();
conn.Close();
conn.Dispose();
jcjcjc
Member
64 Points
639 Posts
Re: How to get parameter in url ( by C# for .net)
Feb 07, 2007 05:52 AM|LINK
the first page is writted with VB by other people ( I can't modify it..)
if I did
a=Request.QueryString("ids")
b= Request.QueryString("val")
then I can get a=18 , b=100 is it correct??
Haissam
All-Star
37421 Points
5632 Posts
Re: How to get parameter in url ( by C# for .net)
Feb 07, 2007 06:11 AM|LINK
if you have this link below
response.redirect("a.aspx?ids=1&val=100",true)
a=Request.QueryString("ids")
b= Request.QueryString("val")
a = 1
b = 100
HC
MCAD.NET
| Blog |
jcjcjc
Member
64 Points
639 Posts
Re: How to get parameter in url ( by C# for .net)
Feb 07, 2007 06:38 AM|LINK
hi, how do I know which should I put it in response.redirect( )?
I have 2 page now ( a is writted by VB .. I can't modify it.. , b is writted by C#)
page a is shows many title... and once user click one of them it will direct to page b. page b will shows content which user click from page a..
so that's why I'm wondering .. is it ok? get parameter in url when we are in page b...