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

client side script with server side controls

P: n/a

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.StringBuilder

chkExpDate.Attributes.Add("onclick", "alertmsg()")
scriptString.Append("<script language=JavaScript> function alertmsg()
{")
scriptString.Append("alert('hi'); }<")
scriptstring.Append("/" + "script>"
s = scriptstring.ToString()

Page.RegisterStartupScript("startup", 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!
Jul 20 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Cathryn Lindner wrote:
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.
<script type="text/javascript">
<!--
function showHide(
/** @argument object */ o,
/** @argument boolean */ b)
/**
* @author (C) 2003 Thomas Lahn &lt;sh*********@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.visibility != "undefined")
o.style.visibility = b ? "visible" : "hidden";
}
//-->
</script>
<form ...>
...
<input
type="checkbox"
checked
...
onclick="showHide(this.form.elements['foobar'], this.checked);"
...
<input
name="foobar"
...>
</form>
The checkbox is a server control (asp:checkbox...).
You probably do not need it.
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.StringBuilder

chkExpDate.Attributes.Add("onclick", "alertmsg()")
scriptString.Append("<script language=JavaScript> function alertmsg()
{")
scriptString.Append("alert('hi'); }<")
scriptstring.Append("/" + "script>"
s = scriptstring.ToString()

Page.RegisterStartupScript("startup", s)

End Sub
That is VBScript, supported only by IE when client-side, and even not
required here.
I used this as a test to make sure the server control was running the
script.


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
Jul 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.