Solved

Fill an Hidden field Value with a QueryString value

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
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.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

816 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

11 Experts available now in Live!

Get 1:1 Help Now