reference a WebControl from client side

BluewaterRocket

New member
Joined
Mar 13, 2003
Messages
3
Location
Florida
Is it possible to set a property in an ASP WebControl from a client side script ?(i.e. Jscript or VBScript). Id like to change the value of the visibility property of a CheckBoxList based upon another checkbox webcontrol event (onChange).

I tried adding an event attribute to the web control (the checkbox) as follows:

chkEmail.Attributes.Add("onchange", "emailDisplay();")

The above was placed in Page_Load

The emailDisplay() script is put in the HEAD of the document as follows:

<script language="VBScript">
Sub emailDisplay ()
if chkEmail.checked = true then
CheckBoxListEmail.Visible = true
else
CheckBoxListEmail.Visible = false
end if

end sub
</script>

Im a pretty green newbie with ASP and HTML scripting, I suspect the semantics of the script are not correct . Dont know if its possible to reference web controls from this client side script.

I load the page w/ visible=false, changing the checkbox does not change the CheckBoxList visible property to true.

Any help appreciated
 
WebControl is server site control, I do not think you can act with it from client site script.

What do you want to do actually? There must be a way for you to solve your problem.

Maybe you need HTML control rather than Web control
 
You should try and look up some tutorials on ASP.NET (try www.asp.net to start with).

What you want to do in this situation is set the AutoPostBack property in your CheckBox to true, and make an OnCheckedChanged event. Then when the user checks the CheckBox, itd respond appropraitely.

Heres basically how you do it;
C#:
<Script runat="Server" Language="C#">
void myChk1_CheckedChanged(object sender, EventArgs e) {
   if (myChk1.Checked)
      ChkList.Visible = false;
   else
      ChkList.Visible = true;
}
</Script>

<html>
<body>

<form Runat="Server">
<asp:CheckBox
id="myChk1"
OnCheckedChanged="myChk1_CheckedChanged" 
AutoPostBack="true"
Checked="true"
Runat="Server" />

<asp:CheckBoxList id="ChkList" Runat="Server" visible="false">
   <asp:ListItem Text ="Item1" />
   <asp:ListItem Text="Item2" />
</asp:CheckBoxList>
</form>

</html>
</body>
 
Anyway, there is not client site script, it run at server (Runat=Server).

This is actually same if you use code-behind concept
 
Back
Top