locked
How do I get a hiddenfield id name in default.aspx.cs? RRS feed

  • Question

  • <asp:TemplateField HeaderText="Customer ID">
        <ItemTemplate>
            <asp:HiddenField runat="server" visible="true" ID ="HiddenField2"   Value='<%#Eval("Customer ID") %>'   ></asp:HiddenField>
                <asp:Label runat="server" ID="HiddenField1"  Text ='<%#Eval("Customer ID")%>' Visible="true" ></asp:Label>
        </ItemTemplate>
    </asp:TemplateField>
    the above code is default.aspx code
    • Moved by Kristin Xie Thursday, August 13, 2015 8:02 AM
    Wednesday, August 12, 2015 1:23 PM

Answers

All replies

  • http://forums.asp.net/

    You should post to the correct forum for help.

    • Proposed as answer by Just Karl Thursday, August 13, 2015 5:45 PM
    • Marked as answer by Just Karl Friday, September 4, 2015 9:47 PM
    Wednesday, August 12, 2015 3:54 PM

  • So for example if you wanted to add show a value from a textbox on a click of a button I would do:

    btnTest.Attributes.Add("onClick", "alert(document.getElementById('" + txtTextBox.ClientID + "').value);");


    Hopefully I didn't mistype anything.  Notice the single quote and double quote at start of getElementById bracket and before the end bracket.  This makes the javascript get the client generated name so that the getElementById function is looking for the correct name.

    Wednesday, August 12, 2015 4:06 PM
  • thanks for your replay..

    my problem is I created gridview column with hiddenfield and that hidden field id name "hiddenfield1"

    i am not getting any problem in .aspx file

    but when I am wrote code for pageload that time I am not getting hidden filed Id("hiddenfield1")

    please help me i can i get,,,,,,

    Thanks

    Wednesday, August 12, 2015 4:24 PM
  • please help me i can i get,,,,,,

    http://forums.asp.net/

    The horse can be lead to the water, but it's up to the horse to take the drink.

    Wednesday, August 12, 2015 5:49 PM
  • You will not get it on page load.

    Please iterate your items in gridview.

    something like below code.

    foreach(item  in griview.Items){ 
    Lable test = (Lable )item.findcontrol("hiddenfield1");
    // do operations on label
    }

    Wednesday, August 12, 2015 5:50 PM