Solved

Fill an Hidden field Value with a QueryString value

Posted on 2011-03-04
5
1,000 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

763 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