Home All Groups Group Topic Archive Search About
Author
31 Mar 2005 7:35 PM
jthornby
Is there any way to manipulate the content of a web control in client side
jscript that can propogate to the server?  Specifically, I'm trying to
increment or decrement the value in a text box when one of a set of check
boxes are checked and I don't want the overhead of going back to the server

Thanks

Author
1 Apr 2005 2:44 PM
Ken Cox [Microsoft MVP]
You can do that nicely with a little Javascript which you output from your
codebehind. I've create a demo sample below that might get you started.

Let us know if this helps?

Ken
Microsoft MVP [ASP.NET]
Toronto

    Private Sub Page_Load _
    (ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles MyBase.Load
        Dim sb As New System.Text.StringBuilder
        sb.Append("<script>")
        sb.Append("function AddChks()")
        sb.Append("{")
        sb.Append("var intChkTotal=0;")
        sb.Append("if (document.forms[0].CheckBox1.checked==true)")
        sb.Append("{")
        sb.Append("intChkTotal = intChkTotal + 1")
        sb.Append("}")
        sb.Append("if (document.forms[0].CheckBox2.checked==true)")
        sb.Append("{")
        sb.Append(" intChkTotal = intChkTotal + 1")
        sb.Append("}")
        sb.Append("if (document.forms[0].CheckBox3.checked==true)")
        sb.Append("{")
        sb.Append(" intChkTotal = intChkTotal + 1")
        sb.Append("}")
        sb.Append("document.forms[0].TextBox1.value=intChkTotal;")
        sb.Append("}")
        sb.Append("</script>")
        Page.RegisterClientScriptBlock("myscript", sb.ToString)
        CheckBox1.Attributes.Add("onclick", "AddChks()")
        CheckBox2.Attributes.Add("onclick", "AddChks()")
        CheckBox3.Attributes.Add("onclick", "AddChks()")
    End Sub

    Private Sub Button1_Click _
    (ByVal sender As System.Object, _
    ByVal e As System.EventArgs) _
    Handles Button1.Click
        Label1.Text = TextBox1.Text
    End Sub
      <form id="Form1" method="post" runat="server">
            <p>
                <asp:checkbox id="CheckBox1"
runat="server"></asp:checkbox></p>
            <p>
                <asp:checkbox id="CheckBox2"
runat="server"></asp:checkbox></p>
            <p>
                <asp:checkbox id="CheckBox3"
runat="server"></asp:checkbox></p>
            <p>
                <asp:textbox id="TextBox1" runat="server"></asp:textbox></p>
            <p>
                <asp:button id="Button1" runat="server"
Text="Button"></asp:button></p>
            <p>
                <asp:label id="Label1" runat="server">Label</asp:label></p>
        </form>

Show quoteHide quote
"jthornby" <jthor***@discussions.microsoft.com> wrote in message
news:E27DAB9E-3BB1-4650-86C1-08547245DA0A@microsoft.com...
> Is there any way to manipulate the content of a web control in client side
> jscript that can propogate to the server?  Specifically, I'm trying to
> increment or decrement the value in a text box when one of a set of check
> boxes are checked and I don't want the overhead of going back to the
> server
>
> Thanks

Bookmark and Share

Post Thread options