locked
Get Unique ID of label control inside GridView from javascript RRS feed

  • Question

  • User1647250948 posted

    Hi

    I have a label control inside a grid view Itemtamplate. I want to set value of label  from javascript at page load.  Suppose I have..

    <asp:GridVew id="Grid" >

        <ItemTamplate>

               <asp:Label id="lblDate" />

         </ItemTamplate>

    </asp:GridVew>

    How can I get unique Id of label control? I am trying by  

    document.getElementById('<%= this.Grid.ClientID%>_lblDate')


    I found that unique id of label from html page are as follows........

    ct0_contentplaceholde001_Grid_ctl02_lblDate

    ct0_contentplaceholde001_Grid_ctl03_lblDate

    here 1st section is Grid id ...and middle section is UNKNOWN and 3rd is label name....... Any suggestion?




    Sunday, November 14, 2010 11:11 PM

Answers

  • User1266497125 posted

    Hi,

    The first part ct0_contentplaceholde001 appears because most probably you are using Master pages. The second part is the grid and the last part is your label. Instead of calling ClientID, try calling UniqueID. Eg. document.getElementById('<%= lblDate.UniqueID %>');

    However, if you have multiple rows (and you do, _Grid_ctl02, _Grid_ctl03), you will have to figure out how to get hold of that one particular lblDate.

    Regards,

    Huske

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, November 15, 2010 3:20 AM