Send a suggestion!

We're building a brand new version of the site, and we'd love to hear your ideas

Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

How to assign a value to hidden field using javascript in asp.net

Last post 05-22-2008 4:48 AM by devichandran. 6 replies.
Page 1 of 1 (7 items)
Sort Posts: Previous Next
  • 05-16-2008 11:24 AM

    How to assign a value to hidden field using javascript in asp.net

    Hi,

       I am trying to assign a value to a hidden field by using the following code but its not working.So can anyone give some better suggestion.

    function hidval(frm,val)

    {

      frm.hidden1.value=val

    }

    <body onload="BLOCKED SCRIPThidval(this.form,<%=value%>)">

    <input type="hidden" name="hidden1" value="">

     /// In the code Behind I am calling the hidden value as follows

    dim var = request.form("hidden1")

    but the above code is not working so please help me to solve this issue.

    • Post Points: 10
  • Advertisement

    • Red Gate Software

    Advertisement

    Want to boost your .NET application performance?

    Some developers always seem to write efficient and lightening-fast code. What is their secret? It’s ANTS Profiler. “We improved the performance of the application up to 10 times” Dan Ports, Intrigma.

    Try it for yourself now.

  • 05-17-2008 10:40 PM In reply to

    Re: How to assign a value to hidden field using javascript in asp.net

    Hi there,

    <input id="HiddenField1" type="hidden" value="" runat="server" />

    protected void Page_Load(object sender, EventArgs e)
    {
    HiddenField1.Value = "1";
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
    Response.Write(HiddenField1.Value);
    }
    Regards,
    Mehdi Golchin
    • Post Points: 10
  • 05-19-2008 5:33 AM In reply to

    Re: How to assign a value to hidden field using javascript in asp.net

     

    Hi, In the code behind I am not getting Hiddenfield's Value by inheriting its property.So its not working ya.

     

     

    • Post Points: 10
  • 05-21-2008 3:52 AM In reply to

    • Freon22
    • Top 200 Contributor
    • Joined on 06-22-2005
    • United States
    • Addicted Member
    • Points 725

    Re: How to assign a value to hidden field using javascript in asp.net

     You are going to need to use an ID with your hidden input field. In the example below I added a value to the hidden input field and then called it again and put it into an alert to display it.

     

    <head runat="server">

    <title>Untitled Page</title>

     

    <script type="text/javascript">

     

    function SetValue()

    {

    document.getElementById(
    'Hidden1').value = "testing !!!!!";

     

    alert(document.getElementById(
    'Hidden1').value);

    }

     

    </script>

     

    </head>

    <body onload="SetValue();">

    <form id="form1" runat="server">

    <div>

    <input id="Hidden1" type="hidden" value="" />

    </div>

    </form>

    • Post Points: 10
  • 05-21-2008 6:02 AM In reply to

    Re: How to assign a value to hidden field using javascript in asp.net

    Hi,

      Thank You So Much For Your Reply Ya.In The Above Code You Are Assigning Value To a Hidden Field Inside a JavaScript, Thats Fine.But The Problem Is I Need To Pass a Parameters From The Code Behind File To The JavaScript Function.So How Can I Do It?

    • Post Points: 10
  • 05-21-2008 2:17 PM In reply to

    • Freon22
    • Top 200 Contributor
    • Joined on 06-22-2005
    • United States
    • Addicted Member
    • Points 725

    Re: How to assign a value to hidden field using javascript in asp.net

    I see your problem. You know that ASP is server side code and javascript is client side code. You can not access HTML controls with ASP and you can not access ASP controls with Javascript. But since ASP does output HTML to the browser, once it does that then you can access it with Javascript. So if you use a ASP hidden control you can set the value in your codebehind then you can access it with javascript from the HTML.

    <asp:HiddenField ID="HiddenField1" runat="server" Value="" />

    CodeBehind

    protected void Page_Load(object sender, EventArgs e)

    {

     if (!Page.IsPostBack)

    {

    HiddenField1.Value =
    "testing";

    }

    Now you can use javascript on it. You can get it value with javascript, you can change its value to something else and with a post back ASP can get the new value that you inputted with javascript. 

     function SetValue()

    {

    alert(document.getElementById('HiddenField1').value);

    }

    Hope this helps!

    • Post Points: 10
  • 05-22-2008 4:48 AM In reply to

    Re: How to assign a value to hidden field using javascript in asp.net

     

    Hi,

       With Help Of Your Above Code, I Have Solved My Problem.

    Thank You So Much Ya.

     

    Regards,

    Devi.C 

     

    • Post Points: 5
Page 1 of 1 (7 items)