locked
Access QueryString Object in ASPX Page RRS feed

  • Question

  • User-1509636757 posted

    Can anybody help me with: "how do i access QueryString Object in ASPX page?" 

    Wednesday, January 9, 2008 10:03 PM

All replies

  • User853058385 posted

    // "?action=view&section=info&id=123&debug"
    var url = location.search;
    // 123
    var id = $.query.get('id');
    // true
    var debug = $.query.get('debug');
    // 123
    var idAlso = $.query['id'];
    // "?action=do&section=5&id=123"
    var newUrl = $.query.set("section", 5).set("action", "do").toString();
    // "?action=view&section=info&id=123&type=string"
    var newQuery = "" + $.query.set('type', 'string');
    // "?action=view&section=info&id=123"
    var oldQuery = $.query.toString();
    // ?action=view&section=info&id=123
    var oldQuery2 = $.query;
    // ?action=view&section=info&id=123&type=string
    var newerQuery = $.query.set('type', 'string', true);
    // "?action=view&section=info&id=123&type=string"
    var notOldQuery = $.query.toString();
    // ?action=view&section=info&id=123
    var oldQueryAgain = $.query.set("type", null, true);
    // ""
    var emptyQuery = $.query.empty();
    // ?action=view&section=info&id=123
    var stillTheSame = $.query.copy();

    Wednesday, January 9, 2008 10:27 PM
  • User-1509636757 posted

    i tried as..

    <asp:TextBox ID="TextBox1" runat="server" Text='<%# Request.QueryString["CategoryID"] %>'></asp:TextBox> 

    but it is not working./. 

    Wednesday, January 9, 2008 11:40 PM
  • User-908924113 posted

    Do it in the code behind...

    Wednesday, January 9, 2008 11:49 PM
  • User-908924113 posted
    if (Request.QueryString["CategoryID"] != null)

    {

    TextBox1.Text = Request.QueryString[
    "CategoryID"].ToString(); ;

    }

    Wednesday, January 9, 2008 11:50 PM
  • User-1509636757 posted

     that is the restriction.... i am not suppose to in code behind... i have to do it in ASPX page only./.

    Wednesday, January 9, 2008 11:52 PM
  • User200962433 posted

    Hi,

    I apologise if I am getting this all wrong, but why are you not trying to use the page load event? I mean you are at the end setting the querystring value to a Server side control, So why not execute it on the page load event.

    Hope this helps to solve your problem.

    Good Luck [yes]

    Regards

    Vineed

    Wednesday, January 9, 2008 11:55 PM
  • User-908924113 posted

    Request.QueryString("values")(1)

    Wednesday, January 9, 2008 11:56 PM
  • User-908924113 posted

    Request.QueryString("values")(1)

    <asp:TextBox ID="TextBox1" runat="server" Text='<%# Request.QueryString("values")(1) %>'></asp:TextBox> 

    SHOULD WORK :-)

    Wednesday, January 9, 2008 11:58 PM
  • User-1509636757 posted

    but why are you not trying to use the page load event?
     

    i am not suppose to in code behind... i HAVE to do it in ASPX page only./.

    Wednesday, January 9, 2008 11:59 PM
  • User-1509636757 posted

    Request.QueryString("values")(1)

    <asp:TextBox ID="TextBox1" runat="server" Text='<%# Request.QueryString("values")(1) %>'></asp:TextBox> 

     

    thanx for reply 

    in C# i tried both way as...

    <asp:TextBox ID="TextBox1" runat="server" Text='<%# Request.QueryString["CategoryID"](1) %>'></asp:TextBox>

    <asp:TextBox ID="TextBox1" runat="server" Text='<%# Request.QueryString["CategoryID"][1] %>'></asp:TextBox> 

    but its not working./. 

    Thursday, January 10, 2008 12:01 AM
  • User-908924113 posted

    Have you passed the CategoryID from the previous page as CategoryID in the querystring? If so then it should work in your case itself ..without the (1) because you are passing the ID itself. values(1) implies the 1st querystring value.

    Thursday, January 10, 2008 12:05 AM
  • User-1509636757 posted

    Have you passed the CategoryID from the previous page as CategoryID in the querystring?
     

    Yes.. i am passing the categoryID from previous page, as i can access in javascript...as

        function test()
        {
            var var1 = '<%= Request.QueryString["CategoryID"] %>';
            alert(var1);
        }

    it gives me alert with correct categoryID... but somehow its not working in ASPX tag./. 

    Thursday, January 10, 2008 12:07 AM
  • User-908924113 posted

    Response.Redirect("yourpage.aspx?somevariable=something&ContractID="+txtContractID.Text); is required in the previous page to access the querystring value in this page...

     

    Thursday, January 10, 2008 12:10 AM
  • User-908924113 posted

    Ohoh... Are you loading this page? I mean as a popup? Because probably the page is being rendered before you set the value

    Thursday, January 10, 2008 12:12 AM
  • User200962433 posted

    Hi,

    I have found some articles on accessing querystring using client side javascript.

    http://www.netlobo.com/url_query_string_javascript.html

    http://forums.asp.net/p/362134/362145.aspx#362145

    Hope this helps

    Good Luck [yes]

    Regards

    Vineed

    Thursday, January 10, 2008 12:15 AM
  • User-908924113 posted

    and if you can use javascript the best thing would be to find the control with window.document.GetElementByID('Textbox1').value='<%= Request.QueryString["CategoryID"] %>'>

    note the use of valua and not Value or Text

    :-)

    Thursday, January 10, 2008 12:16 AM
  • User-908924113 posted

    and if you can use javascript the best thing would be to find the control with window.document.GetElementByID('Textbox1').value='<%= Request.QueryString["CategoryID"] %>'>

    note the use of valua and not Value or Text

    :-)

    I shall be better than me.
    Thursday, January 10, 2008 12:17 AM
  • User-1509636757 posted

     i am posting my complete code...

    on first page Default.aspx; i am passing categoryID... on a button click

        protected void Button1_Click(object sender, EventArgs e)
        {
            Response.Redirect("Default2.aspx?CategoryID=10");       
        }

     

    and on second page Default2.aspx, i try to access QueryString in ASPX page as...

    <head runat="server">
        <title>Untitled Page</title>
        <script type="text/javascript" language="javascript">
        function test()
        {
            var var1 = '<%= Request.QueryString["CategoryID"] %>';
            alert(var1);
        }
       
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <asp:TextBox ID="TextBox1" runat="server" Text='<%# Request.QueryString["CategoryID"] %>'></asp:TextBox>           
            </div>
        </form>
    </body>
    </html>

     

    actually the purpose to do this is... i am having an adrotator on second page... and from first page i will get the categoryID and based on that categoryID; i have to give the AdvertisementFile (xml file) to this adtotator... so i write as...

    <asp:AdRotator AdvertisementFile='<%# String.Format("~/skins/Skin_15/ProductAds-{0}.xml", Request.QueryString["CategoryID"]) %>' ID="ProductAdRotator" runat="server" BorderWidth="1" BorderColor="LightGray" BorderStyle ="Solid" Width = "" Height="" /> 

    Thursday, January 10, 2008 12:17 AM
  • User-908924113 posted

    Please try my javascrpit function...

    Thursday, January 10, 2008 12:20 AM
  • User-908924113 posted

    Please try my javascrpit function... Your code looks fine

    Thursday, January 10, 2008 12:20 AM
  • User-908924113 posted

    If that helped do mark as answer :-)

    Thursday, January 10, 2008 12:29 AM
  • User-1509636757 posted

     i should thank you all for your prompt replies.... but still i am not able to solve the problem....

    actually the purpose to do this is... i am having an adrotator on second page... and from first page i will get the categoryID and based on that categoryID; i have to give the AdvertisementFile (xml file) to this adtotator... so i write as...

    <asp:AdRotator AdvertisementFile='<%# String.Format("~/skins/Skin_15/ProductAds-{0}.xml", Request.QueryString["CategoryID"]) %>' ID="ProductAdRotator" runat="server" BorderWidth="1" BorderColor="LightGray" BorderStyle ="Solid" Width = "" Height="" />

    i tried the solution given in QueryString Value and the TEXT attribute of a TextBox - ASP.NET Forums but that is not working./.

     

    Thursday, January 10, 2008 12:31 AM
  • User1761776108 posted

     try this,

    <asp:TextBox ID="TextBox1" runat="server" Text='<%= Request.QueryString["CategoryID"] %>'></asp:TextBox>

    Thursday, January 10, 2008 12:32 AM
  • User-46028669 posted

    Check this out...

    http://www.dotnetuncle.com/Aspnet/60_pass_value.aspx

    Thursday, January 10, 2008 12:38 AM
  • User-908924113 posted

    Final try, parse it to string in your Ad Rotator.

    Thursday, January 10, 2008 12:46 AM
  • User-1509636757 posted

     try this,

    <asp:TextBox ID="TextBox1" runat="server" Text='<%= Request.QueryString["CategoryID"] %>'></asp:TextBox>

     

    :-(

    not working./.

    Thursday, January 10, 2008 12:51 AM
  • User853058385 posted

    u can use folowing  javascript it will return valye of querystring

    function Query()

    {

    var is_input = document.URL.lastIndexOf('=');

    var addr_str = document.URL.substring(is_input+1, document.URL.length);

    var mid = document.URL.lastIndexOf

    alert( addr_str);

    return addr_str;

    }

    Thursday, January 10, 2008 1:19 AM
  • User200962433 posted

    Hi Kaushal,

    I think I have some sort of a solution. See, I thnk your main problem was that you wanted the AdRotator object to have the value of QueryString. So, I have some sort of a solution

    In you SecondPage i.e Default2.aspx add the following jaavscript code

    function fnLoadAd()

    {

    var AdvertObj = document.getElementById("ProductAdRotator");

    AdvertObj.AdvertisementFile = <yourfilepath> + '<%= Request.QueryString["CategoryID"] %>' + ".xml";

    alert(AdvertObj.AdvertisementFile)

    }

    Execute this function on the body onload event and I think it will solve your problem. I have tried it on my machine and it worked fine.

    Hope this helps to solve your problem

    Good Luck [yes]

    Regards

    Vineed

    Thursday, January 10, 2008 1:26 AM
  • User853058385 posted
    <html xmlns="http://www.w3.org/1999/xhtml" >

    <head runat="server">

    <title>Untitled Page</title>

    <script language="javascript" type="text/javascript" >

     function query()

    {

    var is_input = document.URL.lastIndexOf('=');

    var addr_str = document.URL.substring(is_input+1, document.URL.length);var mid = document.URL.lastIndexOf

    alert( addr_str);

    document.getElementById(
    'TextBox1').value = addr_str;

    }

    </script>

    </head>

    <body OnLoad="query()" >

    <form id="form1" runat="server">

    <div>

    <asp:TextBox ID="TextBox1" runat="server" ></asp:TextBox>

    </div>

    </form> </body>

    </html>

    Thursday, January 10, 2008 1:43 AM
  • User106494309 posted

    hey,

    i'm getting error in this line  <asp:hyperlink runat="server" NavigateUrl='<%# String.Format("~/add.aspx?id={0}",Session["ID"]) %>'>ADD</asp:hyperlink>,

    can u help me

    Monday, December 30, 2013 6:27 AM
  • User-1655119906 posted

    <a target="_blank" href="xyz.aspx?regid=<%= Request.QueryString["regid"]%>">

    Try something like that it will surely work

    Sunday, September 13, 2020 12:34 PM