java script for runat="server" controls

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • raghulvarma
    New Member
    • Oct 2007
    • 90

    java script for runat="server" controls

    if I type the code as
    [HTML]<input type="text" name="txtbox" >[/HTML]
    and make the script language as
    [CODE=javascript]function empty()
    {
    if(document.For m1.txtbox.value =="")
    {
    alert("should not be blank");
    return false;
    }
    }[/CODE]
    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 ...
    Last edited by gits; Mar 17 '08, 07:49 AM. Reason: added code tags
  • vee10
    New Member
    • Oct 2006
    • 141

    #2
    Hi ,

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


    Originally posted by raghulvarma
    if I type the code as
    <input type="text" name="txtbox" >
    and make the script language as
    function empty()
    {
    if(document.For m1.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 ...

    Comment

    • malav123
      New Member
      • Feb 2008
      • 217

      #3
      Hi,
      For server controls you can use the script manager.... the form of how to use it is given below,
      ScriptManager.R egisterClientSc riptBlock(Page, Me.GetType(), "Alert", "alert('Message ');", True)
      I think this will help u....

      Comment

      • raghulvarma
        New Member
        • Oct 2007
        • 90

        #4
        Originally posted by raghulvarma
        if I type the code as
        [HTML]<input type="text" name="txtbox" >[/HTML]
        and make the script language as
        [CODE=javascript]function empty()
        {
        if(document.For m1.txtbox.value =="")
        {
        alert("should not be blank");
        return false;
        }
        }[/CODE]
        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.getEle mentById("TextB ox2").value;
        if(isNaN(variab le))
        {
        alert('not a numeric value');
        }
        }

        //IN SIDE CODE BEHIND

        Button1.Attribu tes.Add("onClic k", " return tocheck()");

        this works well but only after two ckicks why is it ?
        thanks in advance

        Comment

        Working...