client side script with server side controls

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Cathryn Lindner

    client side script with server side controls


    I have a web form that has a checkbox on it and a textbox associated
    with it. I want the textbox to be displayed when the checkbox is checked
    and I want this to happen on the client-side instead of posting back to
    the server. The checkbox is a server control (asp:checkbox.. .). I can
    write some codebehind that will display an alert message upon checking
    the box that looks something like this...

    Page_Load...

    Dim s As String
    Dim scriptString As New System.Text.Str ingBuilder

    chkExpDate.Attr ibutes.Add("onc lick", "alertmsg() ")
    scriptString.Ap pend("<script language=JavaSc ript> function alertmsg()
    {")
    scriptString.Ap pend("alert('hi '); }<")
    scriptstring.Ap pend("/" + "script>"
    s = scriptstring.To String()

    Page.RegisterSt artupScript("st artup", s)

    End Sub

    I used this as a test to make sure the server control was running the
    script. But, when I change the script to assess the value of the server
    control checkbox such as checked = true, I get errors and if I just try
    to display the asp:textbox, it doesn't work either.

    Any suggestions?



    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
  • Thomas 'PointedEars' Lahn

    #2
    Re: client side script with server side controls

    Cathryn Lindner wrote:
    [color=blue]
    > I have a web form that has a checkbox on it and a textbox associated
    > with it. I want the textbox to be displayed when the checkbox is checked
    > and I want this to happen on the client-side instead of posting back to
    > the server.[/color]

    <script type="text/javascript">
    <!--
    function showHide(
    /** @argument object */ o,
    /** @argument boolean */ b)
    /**
    * @author (C) 2003 Thomas Lahn &lt;showHide.js @PointedEars.de &gt;
    * @argdescr o Object to show/hide.
    * @argdescr b <code>true</code> shows the object,
    * <code>false</code> or this argument
    * left out hides it. CSS scripting
    * support is required for this to work.
    */
    {
    if (o
    && typeof o.style != "undefined"
    && typeof o.style.visibil ity != "undefined" )
    o.style.visibil ity = b ? "visible" : "hidden";
    }
    //-->
    </script>
    <form ...>
    ...
    <input
    type="checkbox"
    checked
    ...
    onclick="showHi de(this.form.el ements['foobar'], this.checked);"
    ...
    <input
    name="foobar"
    ...>
    </form>
    [color=blue]
    > The checkbox is a server control (asp:checkbox.. .).[/color]

    You probably do not need it.
    [color=blue]
    > I can write some codebehind that will display an alert message upon
    > checking the box that looks something like this...
    >
    > Page_Load...
    >
    > Dim s As String
    > Dim scriptString As New System.Text.Str ingBuilder
    >
    > chkExpDate.Attr ibutes.Add("onc lick", "alertmsg() ")
    > scriptString.Ap pend("<script language=JavaSc ript> function alertmsg()
    > {")
    > scriptString.Ap pend("alert('hi '); }<")
    > scriptstring.Ap pend("/" + "script>"
    > s = scriptstring.To String()
    >
    > Page.RegisterSt artupScript("st artup", s)
    >
    > End Sub[/color]

    That is VBScript, supported only by IE when client-side, and even not
    required here.
    [color=blue]
    > I used this as a test to make sure the server control was running the
    > script.[/color]

    Not the server control is running the JavaScript, the client's
    JavaScript engine is. What you (are trying to) do here is merely
    telling the server to include that script into the code sent to
    the client.


    PointedEars

    Comment

    Working...