Link to home
Start Free TrialLog in
Avatar of saturation
saturation

asked on

Fill an Hidden field Value with a QueryString value

I'm trying to get the "ProductID" querystring value on my .NET page and insert it as the value for one of my hidden fields, but it's not filling in anything even though the ProductID is in the querystring with a value.   What am I doing wrong?

<asp:HiddenField ID="dccapv_productid" runat="server" Value="<%= Request.QueryString("ProductID") %>"/>
Avatar of rawinnlnx9
rawinnlnx9
Flag of United States of America image

Request.QueryString["ProductID"].ToString()

I think you need brackets. Just taking a guess though. You could also do this from the codebehind:


dccapv_productid.value=Request.QueryString["ProductID"].ToString();


I know that works.
Avatar of saturation
saturation

ASKER

I tried using your first example and got the same

Parser Error Message: Server tags cannot contain <% ... %> constructs.



I do not have a codebehind page.   Is there another way to do this?
Hi,

Here is an EE thread about the same question.

https://www.experts-exchange.com/questions/25136616/Setting-a-HiddenField-value-from-a-QueryString.html

You cannot set a value using server tags.

Also, using HiddenFields, they are not rendered in the DOM because of visible=false by default.  So you cannot use Javascript to set them.  The solution I propose is this :

Use a Label with style=display:false.  Then, I added a function to the onload of the <body> tag.  And added the Javascript function to your page.  This should set the label dccapv_productid with the querystring value of ProductID.


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title></title>
<script type="text/javascript">
  function SetHiddenField() {
    var d = '<%=Request["ProductID"] %>';
    document.getElementById("<%= dccapv_productid.ClientID %>").innerText = d;
  }
</script>
</head>
<body onload="SetHiddenField();">
    <form id="form1" runat="server" >
        <asp:Label ID="dccapv_productid" runat="server" style="display:none" />
    </form>
  </body>
</html>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Anurag Agarwal
Anurag Agarwal
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
i mean use this value= '<%= .... %>'

<asp:HiddenField ID="dccapv_productid" runat="server" value= '<%= Request.QueryString("ProductID")%>' />