How to get parameter in url ( by C# for .net)http://forums.asp.net/t/1072321.aspx/1?How+to+get+parameter+in+url+by+C+for+net+Wed, 30 Jun 2010 18:59:35 -040010723211566979http://forums.asp.net/p/1072321/1566979.aspx/1?How+to+get+parameter+in+url+by+C+for+net+How to get parameter in url ( by C# for .net) <span>&nbsp; <p><font style="background-color:#ffffff">I would like to <b style="color:black; background-color:#a0ffff"> <font style="background-color:#ffffff">get</font></b> <b style="color:black; background-color:#99ff99"> <font style="background-color:#ffffff">parameter</font></b> of&nbsp;ASP.NET script in <font style="background-color:#ffffff"> <b style="color:black; background-color:#ff9999"><font style="background-color:#ffffff">URL</font></b><br> </font><br> example : /localhost/example.asp?parameter1<br> <br> How can i to <font style="background-color:#ffffff"><b style="color:black; background-color:#a0ffff"><font style="background-color:#ffffff">get</font></b> </font>this <b style="color:black; background-color:#99ff99"><font style="background-color:#ffffff">parameter</font></b> ?</font></p> <p><font style="background-color:#ffffff">can you give me a example? ( using C#) </p> <p><br> Thanks a lot</font><br> </p> <p>&nbsp;</p> <p>JC</p> </span> 2007-02-07T04:39:44-05:001566988http://forums.asp.net/p/1072321/1566988.aspx/1?Re+How+to+get+parameter+in+url+by+C+for+net+Re: How to get parameter in url ( by C# for .net) <p>To get a querystring you can use the Request.Querystring&nbsp;property:</p> <p>Request.Querystring(&quot;parameter1&quot;)</p> 2007-02-07T04:47:53-05:001567020http://forums.asp.net/p/1072321/1567020.aspx/1?Re+How+to+get+parameter+in+url+by+C+for+net+Re: How to get parameter in url ( by C# for .net) <p>Actually in C# it would be:</p> <pre class="prettyprint">//this takes request parameters only from the query string Request.QueryString[&quot;parameter1&quot;]; //this one works for bot - form and query string Request[&quot;parameter1&quot;];</pre>&nbsp; 2007-02-07T05:13:49-05:001567029http://forums.asp.net/p/1072321/1567029.aspx/1?Re+How+to+get+parameter+in+url+by+C+for+net+Re: How to get parameter in url ( by C# for .net) <p>In Page1.aspx</p> <p>Response.Redirect(&quot;Page2.aspx?param1=Test&quot;);</p> <p>In Page2.aspx</p> <p>if (Request.QueryString[&quot;param1&quot;] != null)<br> &nbsp; Response.Write(&quot;From Page1 param1 value=&quot; &#43; Request.QueryString[&quot;param1&quot;]);</p> <p>Thanks</p> 2007-02-07T05:17:44-05:001567043http://forums.asp.net/p/1072321/1567043.aspx/1?Re+How+to+get+parameter+in+url+by+C+for+net+Re: How to get parameter in url ( by C# for .net) <p><span style="font-size:10pt; font-family:Arial">lol, sometime by sitting with a VB.Net project at the moment can destroy the way of writing C#, </span><span style="font-size:10pt; font-family:Arial">or the syntax can in a hurry be written wrong ;)</span></p> <p><span style="font-size:10pt; font-family:Arial">To add something vaulable to this post, you can also use Request.Params[&quot;parameter1&quot;]</span></p> 2007-02-07T05:23:30-05:001567061http://forums.asp.net/p/1072321/1567061.aspx/1?Re+How+to+get+parameter+in+url+by+C+for+net+Re: How to get parameter in url ( by C# for .net) <p>In the first page</p> <p>response.redirect(&quot;a.aspx?ids=1&amp;val=100&quot;,true)</p> <p>and in the second page that is a.aspx</p> <p>a=Request.QueryString(&quot;ids&quot;)&nbsp;</p> <p>b=&nbsp;Request.QueryString(&quot;val&quot;)</p> 2007-02-07T05:30:51-05:001567065http://forums.asp.net/p/1072321/1567065.aspx/1?Re+How+to+get+parameter+in+url+by+C+for+net+Re: How to get parameter in url ( by C# for .net) <p>thanks for you all</p> <p>&nbsp;I'm sorry... but I still can't understand... </p> <p>how about this example of url&nbsp; : <a href="http://forums.asp.net/AddPost.aspx?PostID=1566979"> http://forums.asp.net/AddPost.aspx?PostID=1566979</a></p> <p>&nbsp;I want&nbsp;to get &quot;<u><font color="#800080">1566979&quot;</font></u></p> <p>&nbsp;is it correct&nbsp; Request.Querystring(&quot;<u><font color="#800080">PostID</font></u>&quot;)&nbsp;&nbsp;&nbsp; and I can get 1566979</p> <p>&nbsp;</p> <p>once I get postID (1566969) I'll replace the X as 1566979&nbsp; </p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string strConn = &quot;data Source=x.x.x.x;user=sa;password=1234;initial catalog=Member&quot;;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string strSQL = &quot;select Subject,nContent from pro_News where Member_no = &quot;<strong><u>x</u></strong>&quot; &quot;;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SqlConnection conn = new SqlConnection(strConn);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SqlCommand cmd = new SqlCommand(strSQL,conn);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cmd.CommandType = CommandType.Text;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; conn.Open();<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SqlDataReader dr = cmd.ExecuteReader();<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; while (dr.Read())<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Label1.Text= (dr[&quot;Name&quot;].ToString());<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Label2.Text = (dr[&quot;Address&quot;].ToString());<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cmd.Dispose();<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; conn.Close();<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; conn.Dispose();</p> <p>&nbsp;</p> <p>&nbsp;</p> <p><u><font color="#800080"></font></u>&nbsp;</p> 2007-02-07T05:36:04-05:001567086http://forums.asp.net/p/1072321/1567086.aspx/1?Re+How+to+get+parameter+in+url+by+C+for+net+Re: How to get parameter in url ( by C# for .net) <p>the first page is writted with VB by other people ( I can't modify it..)</p> <p>if I did </p> <p>a=Request.QueryString(&quot;ids&quot;)&nbsp;</p> <p>b=&nbsp;Request.QueryString(&quot;val&quot;)</p> <p>then I can get&nbsp;&nbsp;&nbsp; a=18 , b=100 is it correct??</p> 2007-02-07T05:52:12-05:001567108http://forums.asp.net/p/1072321/1567108.aspx/1?Re+How+to+get+parameter+in+url+by+C+for+net+Re: How to get parameter in url ( by C# for .net) <p>if you have this link below</p> <p>response.redirect(&quot;a.aspx?ids=1&amp;val=100&quot;,true)</p> <p>a=Request.QueryString(&quot;ids&quot;)&nbsp;</p> <p>b=&nbsp;Request.QueryString(&quot;val&quot;)</p> <p>a = 1</p> <p>b = 100</p> <p>HC</p> 2007-02-07T06:11:47-05:001567135http://forums.asp.net/p/1072321/1567135.aspx/1?Re+How+to+get+parameter+in+url+by+C+for+net+Re: How to get parameter in url ( by C# for .net) <p>hi, how do I know which should I put it in response.redirect( )?</p> <p>I have 2 page now&nbsp; ( a is writted by VB .. I can't modify it.. , b is writted by C#)</p> <p>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..</p> <p>&nbsp;so that's why I'm wondering .. is it ok? get parameter in url when we are in page b...</p> 2007-02-07T06:38:47-05:001567164http://forums.asp.net/p/1072321/1567164.aspx/1?Re+How+to+get+parameter+in+url+by+C+for+net+Re: How to get parameter in url ( by C# for .net) <p></p> <blockquote><span class="icon-blockquote"></span> <h4>e_screw</h4> In Page1.aspx<br> Response.Redirect(&quot;Page2.aspx?param1=Test&quot;);<br> In Page2.aspx<br> if (Request.QueryString[&quot;param1&quot;] != null)<br> &nbsp; Response.Write(&quot;From Page1 param1 value=&quot; &#43; Request.QueryString[&quot;param1&quot;]);</blockquote> <p></p> <p>This is how you pass parameters from one page to another in C#</p> <p></p> <blockquote><span class="icon-blockquote"></span> <h4>jcjcjc</h4> hi, how do I know which should I put it in response.redirect( )?<br> I have 2 page now&nbsp; ( a is writted by VB .. I can't modify it.. , b is writted by C#)<br> 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..<br> &nbsp;so that's why I'm wondering .. is it ok? get parameter in url when we are in page b...</blockquote> <p></p> <p>By default VS doesnt allow multiple language compilation. If you want to have mutiple language compilation you need to add the following section in web.config file and your code should go into the respective folders under the App_Code</p> <p>&lt;compilation debug=&quot;true&quot;&gt;<br> &nbsp;&nbsp;&nbsp; &lt;codeSubDirectories&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;add directoryName=&quot;VBCode&quot; /&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;add directoryName=&quot;CSCode&quot; /&gt;<br> &nbsp;&nbsp;&nbsp; &lt;/codeSubDirectories&gt;<br> &lt;/compilation&gt;</p> <p>Thanks</p> 2007-02-07T07:04:23-05:001568883http://forums.asp.net/p/1072321/1568883.aspx/1?Re+How+to+get+parameter+in+url+by+C+for+net+Re: How to get parameter in url ( by C# for .net) <p>thank you ~ <img alt="Fredrik N is not online. Last active: Wed, Feb 07 2007, 1:54 AM" src="http://forums.asp.net/Themes/default/images/user_IsOffline.gif" style="border-top-width:0px; border-left-width:0px; border-bottom-width:0px; border-right-width:0px"> <a href="http://forums.asp.net/members/Fredrik&#43;N.aspx">Fredrik N</a> <a href="http://forums.asp.net/members/fafar.aspx">fafar</a> <a href="http://forums.asp.net/members/e_screw.aspx">e_screw</a> <a href="http://forums.asp.net/members/sreejith77.aspx">sreejith77</a> <a href="http://forums.asp.net/members/Haissam.aspx">Haissam</a>&nbsp; [:D]</p> <p>beause all of your help and patient.. I've resolve my question </p> <p>I just simply add code like below&nbsp;on the second page </p> <p>Request.QueryString[&quot;postID&quot;].ToString()</p> <p>and it does work perfect right now..</p> <p>really appreciate for your help . thanks again ~!![Angel]</p> <p>&nbsp;</p> 2007-02-08T02:07:58-05:001576004http://forums.asp.net/p/1072321/1576004.aspx/1?Re+How+to+get+parameter+in+url+by+C+for+net+Re: How to get parameter in url ( by C# for .net) <p>sorry for asking same question again..</p> <p>I don't know what's going wrong . I use the same way to get prameter from URL and put it on SQL Query string for select data...</p> <p>but it doesn't work at all... label1.text and label2.text seems empty...</p> <p>&nbsp;below is my code... can you point me where I did wrong please? thank you</p> <p>============================================================</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string a= Request.QueryString[&quot;cid&quot;].ToString();&nbsp; // my url is like &quot;http://localhost/news_c.aspx?cid=14&amp;FK=1&quot;</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string strConn = &quot;data Source=x.x.x.x;user=sa;password=1234 ;initial catalog=guestbook&quot;;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string strSQL = &quot;select Subject,nContent from message where cid=&quot; &#43; a;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SqlConnection conn = new SqlConnection(strConn);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SqlCommand cmd = new SqlCommand(strSQL, conn);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cmd.CommandType = CommandType.Text;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; conn.Open();<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SqlDataReader dr = cmd.ExecuteReader();<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; while (dr.Read())<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.Label1.Text = (dr[&quot;Subject&quot;].ToString());<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.Label2.Text = (dr[&quot;nContent&quot;].ToString());<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cmd.Dispose();<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; conn.Close();<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; conn.Dispose();</p> 2007-02-13T06:23:46-05:001576012http://forums.asp.net/p/1072321/1576012.aspx/1?Re+How+to+get+parameter+in+url+by+C+for+net+Re: How to get parameter in url ( by C# for .net) <p>Make sure you are getting the correct value into a. Since you are not getting any exception, seems you are getting the correct value else an exception would be raised for the incorrect sql statement. Also check how many rows are returned by your sql statement. If you have multiple rows returned, the dr.Read() in while will loop through all the rows and sets the label's with the last values in the records returned</p> <p>Thanks</p> 2007-02-13T06:34:35-05:001576015http://forums.asp.net/p/1072321/1576015.aspx/1?Re+How+to+get+parameter+in+url+by+C+for+net+Re: How to get parameter in url ( by C# for .net) <p>hm.... I don't know what's going wrong actually...[:S]</p> <p>&nbsp;I move these code from event Page_load to event button_click</p> <p>it does work ... </p> <p>but in previous practice I put code in event page_load it doesn't work..and now it doesn't...</p> <p>&nbsp;</p> 2007-02-13T06:38:42-05:001576042http://forums.asp.net/p/1072321/1576042.aspx/1?Re+How+to+get+parameter+in+url+by+C+for+net+Re: How to get parameter in url ( by C# for .net) <p>thank you e_screw</p> <p>I put a bottom to form and raise a button_click event.</p> <p>and then move code from event-Page_load to event-button_click</p> <p>label1 and label2 will shows correct information which I get from SQL Query after I click bottom..</p> <p>&nbsp;</p> <p>is anything wrong I put the code in event- page_load? how come is doesn't work ? </p> <p>thank you very much </p> <p>&nbsp;</p> <p>&nbsp;</p> 2007-02-13T07:10:22-05:001576069http://forums.asp.net/p/1072321/1576069.aspx/1?Re+How+to+get+parameter+in+url+by+C+for+net+Re: How to get parameter in url ( by C# for .net) <p>The same code should work in the Page_Load also if you are getting the correct value in the cid. Check this line by keeping a break point.</p> <p>string a= Request.QueryString[&quot;cid&quot;].ToString();&nbsp; </p> <p>Thanks</p> 2007-02-13T07:37:21-05:001576080http://forums.asp.net/p/1072321/1576080.aspx/1?Re+How+to+get+parameter+in+url+by+C+for+net+Re: How to get parameter in url ( by C# for .net) <p>thank you e_screw again</p> <p>can you please teach me how to run a break point ?</p> <p>I put a break point on String a= Request.QueryString[&quot;cid&quot;].ToString(); and then run the program</p> <p>nothing happen... is this what I have to do? or should I get any information from set a break point? ( I'm sorry but I really not similiar with this step_</p> <p>thank you very much</p> 2007-02-13T07:51:39-05:001576119http://forums.asp.net/p/1072321/1576119.aspx/1?Re+How+to+get+parameter+in+url+by+C+for+net+Re: How to get parameter in url ( by C# for .net) <p>On the line of code (text cursor on this line)&nbsp;String a= Request.QueryString[&quot;cid&quot;].ToString(); press F9&nbsp; which will keep a break point on that line (the entire line turns brown in color). <br> Now press F5, and when the break point line of code is reached, the execution breaks, and that line turns yellow. Keep cursor on the variable or controls properties on the yellow line and you will see a white tool tip showing its values. You can also use Watch window, to write the expression and look at its value. <br> <br> // Note your break point will hit, only when you access that page in which you have kept the break point</p> <p>Thanks</p> 2007-02-13T08:25:57-05:001576150http://forums.asp.net/p/1072321/1576150.aspx/1?Re+How+to+get+parameter+in+url+by+C+for+net+Re: How to get parameter in url ( by C# for .net) <p>thank you !!! very clearly... and I did as the folllow you taught..</p> <p>but I find the problem... break point never hit... so is it mean program never run the event -page_load??</p> <p>&nbsp;</p> <p>I now have 2 webpage&nbsp; new_s and news_c</p> <p>when user click item on new_s&nbsp; page will trun to new_c and shows item's detail which user just clicked...</p> <p>news_c need to get parameter from URL so that can Query which item should be show..</p> <p>&nbsp;</p> <p>&nbsp;but now seems page_load didn't invoke when news_s trun to news_c? right?[:S] </p> <p>&nbsp;</p> <p>thank you again</p> <p>&nbsp;</p> 2007-02-13T08:53:18-05:00