Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Setting HiddenField via jQuery not working in code behind

Setting HiddenField via jQuery not working in code behind

Scheduled Pinned Locked Moved ASP.NET
javascriptsysadminhelpquestion
3 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Gareth H
    wrote on last edited by
    #1

    So i am making a "Delete" button, which is on a gridview. The link calls some javascript, updates the hiddenfield value and then opens a jQuery dialog. In the dialog, there is a "Yes", "No" options. If the user clicks "Yes", i get the value of the hiddenfield and delete the record. Button;

    <a href="#" onclick='LoadDialog(<%# Eval("AccountId") %>)'>Delete</a>

    Javascript;

    function LoadDialog(accountId) {
    $('#<%= HiddenFieldAccountId.ClientID %>').attr('value', accountId);

        $('#dialog').dialog('open'); 
        return false;
    }
    

    Dialog;

    <div id="dialog" title="Delete Account">
    Are you sure you wish to delete this account?<br /><br />
    <asp:HiddenField ID="HiddenFieldAccountId" runat="server" />
    <asp:LinkButton ID="LinkButtonDelete" runat="server" onclick="LinkButtonDelete_Click">Yes</asp:LinkButton> |
    <a href="#" onclick="UnloadDialog()">No</a>
    </div>

    When the "Yes" (LinkButtonDelete) is clicked, i step into the code and look at the hidden field, and this is where i come to the problem. The hidden field value is empty. I've added an alert message to the 'LoadDialog' javascript, and i know the account id is set, its just the code behind cant see it is.

    Regards, Gareth. (FKA gareth111)

    G 2 Replies Last reply
    0
    • G Gareth H

      So i am making a "Delete" button, which is on a gridview. The link calls some javascript, updates the hiddenfield value and then opens a jQuery dialog. In the dialog, there is a "Yes", "No" options. If the user clicks "Yes", i get the value of the hiddenfield and delete the record. Button;

      <a href="#" onclick='LoadDialog(<%# Eval("AccountId") %>)'>Delete</a>

      Javascript;

      function LoadDialog(accountId) {
      $('#<%= HiddenFieldAccountId.ClientID %>').attr('value', accountId);

          $('#dialog').dialog('open'); 
          return false;
      }
      

      Dialog;

      <div id="dialog" title="Delete Account">
      Are you sure you wish to delete this account?<br /><br />
      <asp:HiddenField ID="HiddenFieldAccountId" runat="server" />
      <asp:LinkButton ID="LinkButtonDelete" runat="server" onclick="LinkButtonDelete_Click">Yes</asp:LinkButton> |
      <a href="#" onclick="UnloadDialog()">No</a>
      </div>

      When the "Yes" (LinkButtonDelete) is clicked, i step into the code and look at the hidden field, and this is where i come to the problem. The hidden field value is empty. I've added an alert message to the 'LoadDialog' javascript, and i know the account id is set, its just the code behind cant see it is.

      Regards, Gareth. (FKA gareth111)

      G Offline
      G Offline
      Gareth H
      wrote on last edited by
      #2

      No one got any ideas?, Someone must of had to create a "Confirm" dialog in jQuery and display some data from code behind before...

      Regards, Gareth. (FKA gareth111)

      modified on Tuesday, December 29, 2009 11:06 AM

      1 Reply Last reply
      0
      • G Gareth H

        So i am making a "Delete" button, which is on a gridview. The link calls some javascript, updates the hiddenfield value and then opens a jQuery dialog. In the dialog, there is a "Yes", "No" options. If the user clicks "Yes", i get the value of the hiddenfield and delete the record. Button;

        <a href="#" onclick='LoadDialog(<%# Eval("AccountId") %>)'>Delete</a>

        Javascript;

        function LoadDialog(accountId) {
        $('#<%= HiddenFieldAccountId.ClientID %>').attr('value', accountId);

            $('#dialog').dialog('open'); 
            return false;
        }
        

        Dialog;

        <div id="dialog" title="Delete Account">
        Are you sure you wish to delete this account?<br /><br />
        <asp:HiddenField ID="HiddenFieldAccountId" runat="server" />
        <asp:LinkButton ID="LinkButtonDelete" runat="server" onclick="LinkButtonDelete_Click">Yes</asp:LinkButton> |
        <a href="#" onclick="UnloadDialog()">No</a>
        </div>

        When the "Yes" (LinkButtonDelete) is clicked, i step into the code and look at the hidden field, and this is where i come to the problem. The hidden field value is empty. I've added an alert message to the 'LoadDialog' javascript, and i know the account id is set, its just the code behind cant see it is.

        Regards, Gareth. (FKA gareth111)

        G Offline
        G Offline
        Gareth H
        wrote on last edited by
        #3

        Problem solved. The HiddenField was always returning empty, even if i set it in the code behind. It was because it was located in a panel. Weird, not sure why, but once i moved it from one part of the page to the top (outside of the panel), it worked.

        Regards, Gareth. (FKA gareth111)

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups