Solved

Fill an Hidden field Value with a QueryString value

Posted on 2011-03-04
5
995 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
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 …
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

912 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

18 Experts available now in Live!

Get 1:1 Help Now