By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,710 Members | 1,626 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,710 IT Pros & Developers. It's quick & easy.

java script for runat="server" controls

P: 90
if I type the code as
[HTML]<input type="text" name="txtbox" >[/HTML]
and make the script language as
Expand|Select|Wrap|Line Numbers
  1. function empty()
  2.     {
  3.       if(document.Form1.txtbox.value=="")
  4.          {
  5.     alert("should not be blank");
  6.     return false;
  7.         }
  8.   }
it works well , but If i give the same coding for a runat = "server" it does not work How should I do this ? Is there a possibility for getting the control by getElementById for TextBox as there is no "name" attribute present in ...
Mar 17 '08 #1
Share this Question
Share on Google+
3 Replies


100+
P: 141
Hi ,

for the server controls in the page load event u should add the attributes
example txtbox(if it is server control)
txtbox.Attributes.Add("onchange/onclick/whatever is the event","return empty()");


if I type the code as
<input type="text" name="txtbox" >
and make the script language as
function empty()
{
if(document.Form1.txtbox.value=="")
{
alert("should not be blank");
return false;
}
}
it works well , but If i give the same coding for a runat = "server" it does not work How should I do this ? Is there a possibility for getting the control by getElementById for TextBox as there is no "name" attribute present in ...
Mar 17 '08 #2

malav123
100+
P: 217
Hi,
For server controls you can use the script manager.... the form of how to use it is given below,
ScriptManager.RegisterClientScriptBlock(Page, Me.GetType(), "Alert", "alert('Message');", True)
I think this will help u....
Mar 19 '08 #3

P: 90
if I type the code as
[HTML]<input type="text" name="txtbox" >[/HTML]
and make the script language as
Expand|Select|Wrap|Line Numbers
  1. function empty()
  2.     {
  3.       if(document.Form1.txtbox.value=="")
  4.          {
  5.     alert("should not be blank");
  6.     return false;
  7.         }
  8.   }
it works well , but If i give the same coding for a runat = "server" it does not work How should I do this ? Is there a possibility for getting the control by getElementById for TextBox as there is no "name" attribute present in ...

function tocheck()
{
var variable = document.getElementById("TextBox2").value;
if(isNaN(variable))
{
alert('not a numeric value');
}
}

//IN SIDE CODE BEHIND

Button1.Attributes.Add("onClick", " return tocheck()");

this works well but only after two ckicks why is it ?
thanks in advance
Mar 21 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.