Solved

Fill an Hidden field Value with a QueryString value

Posted on 2011-03-04
5
991 Views
Last Modified: 2012-08-14
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") %>"/>
0
Comment
Question by:saturation
5 Comments
 
LVL 9

Expert Comment

by:rawinnlnx9
ID: 35040575
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.
0
 

Author Comment

by:saturation
ID: 35040601
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?
0
 
LVL 16

Expert Comment

by:BurnieP
ID: 35040924
Hi,

Here is an EE thread about the same question.

http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_25136616.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

0
 
LVL 8

Accepted Solution

by:
Anurag Agarwal earned 500 total points
ID: 35044134
saturation try this (vb.net code)

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

instead of "" use '' single inverted comma

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

0
 
LVL 8

Expert Comment

by:Anurag Agarwal
ID: 35044142
i mean use this value= '<%= .... %>'

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

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now