Hi guys, i done this a few weeks ago but i cant remember the syntax to populate a labels text heres is my HTML
Can someone help me with the syntax its the labels that have required written in them its something lilke 'span[id*=#MainContent_lblUserName' i cant remember the exact syntax
Harrison.Sco...
Member
331 Points
456 Posts
how to set a labels text
Apr 07, 2012 09:23 AM|LINK
Hi guys, i done this a few weeks ago but i cant remember the syntax to populate a labels text heres is my HTML
Can someone help me with the syntax its the labels that have required written in them its something lilke 'span[id*=#MainContent_lblUserName' i cant remember the exact syntax
<div class="accountInfo"> <p style="margin-left:16%"> <label for="MainContent_txtUserName" id="MainContent_UserNameLabel">Username:</label> <input name="ctl00$MainContent$txtUserName" type="text" id="MainContent_txtUserName" class="textEntry" /> <span id="MainContent_lblUserName">required</span> </p> <p style="margin-left: 16%"> <label for="MainContent_txtPassword" id="MainContent_PasswordLabel" style="padding-right:4.5px">Password:</label> <input name="ctl00$MainContent$txtPassword" type="password" id="MainContent_txtPassword" class="passwordEntry" /> <span id="MainContent_lblPassword">required</span> </p> <p class="submitButton"> <input type="submit" name="ctl00$MainContent$LoginButton" value="Log In" id="MainContent_LoginButton" /> </p> </div>Md Eqbal Ans...
Member
186 Points
93 Posts
Re: how to set a labels text
Apr 07, 2012 09:28 AM|LINK
$('#MainContent_txtPassword').text('hello')
This will set the text of that label as hello
Thanks & Best Regards,
Eqbal.
Please mark the post as answer, if you find this useful.
mm10
Contributor
6399 Points
1184 Posts
Re: how to set a labels text
Apr 07, 2012 09:32 AM|LINK
document.getElementById("<%= UserNameLabel.ClientID %>").innerHTML="Text...";mudassarkhan
All-Star
78956 Points
13402 Posts
MVP
Re: how to set a labels text
Apr 07, 2012 10:13 AM|LINK
Even easier way is to use jQuery Wild Card selectors. With Wild Card selector you don't need to worry about the changing ids
$("[id*=UserNameLabel]").html("Your text to be set");
Ref: http://jqueryfaqs.com/Questions/Find-and-select-ASP.Net-Server-Controls-like-Button-TextBox-and-DropDownList-using-jQuery.aspx
Contact me