Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Jun 04, 2009 06:04 AM by rakesh.khuntia
May 10, 2008 12:58 PM|LINK
i am using content page...
i have a control asp:textbox id=myname
i want to write the client script for this field to check against being null
May 10, 2008 01:17 PM|LINK
<asp:TextBox id="txtMyTextBox" runat="Server" Text="1234"></asp:TextBox>
var value = document.getElementById('<%=txtMyTextBox.ClientID%>').value;
As TextBox is server control, so on runtime this control have different client id
'<%=txtMyTextBox.ClientID%>' will return control clientid on runtime
May 10, 2008 05:42 PM|LINK
Is there any reason that you are not using ASP.NET RequiredFieldValidator control?
May 12, 2008 04:50 AM|LINK
i couldnt find a property like required field validator on my buttons property...could you just guide me with this...there is another group as validation group...what is the input type that it expects?say is it the id of my text box that i need to fill
in and if i do that would it validate it against it being null specifiaclly when that button is clicked?
May 12, 2008 05:17 AM|LINK
Check out this link on how to validate controls..
May 12, 2008 05:22 AM|LINK
i tried doing this onto my button's OnClientClick var value = document.getElementById('<%=txtName.ClientID%>').value;alert(value);return false;
May 12, 2008 06:19 AM|LINK
hi gaurav i try ur coding its working pls check r u try like this
May 12, 2008 06:54 AM|LINK
hey i think it is all bcoz of me using content page...this page is a content page...is it possible to write scripts in content page( it doesnt have a head part, only body part)..
May 12, 2008 07:47 AM|LINK
If you are using master page then the server side control id will be changed.
use document.getElementById("ctl00$ContentPlaceHolder1$TextBox1").value=="" to validate the control..
if problem not solved then Check the content page control id by viewing the source & copy the controlid & paste it into getElementById() method.
Here is a sample code..
alert("Please enter the text");
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="return test();" /></td>
Note: Instead of writing the whole code to validate a control,you can use required field validator controls by just setting the few properties..
May 12, 2008 08:00 AM|LINK