Check state on webform

  • Thread starter Thread starter PawelR
  • Start date Start date
P

PawelR

Hello group,
I'm begginer in ASP.net and my question is very simple.
In my webform I have CheckBox (myCB) and DropDownList (myDDL). I want set
myDDL.Enabled =myCB.Checked and show change without refresh
website (without send formular to server) - run this on client site.
Thx
PawelR
 
You can get the client side id for these serverside controls in the code by
using the ClientID attribute for the control. So you can use this to write
the client side code to manipulate this.
 
On client site change state dropdownlist control, but use value from
dropdownlist on server site after send form to server.
 
Thx,
but I don't know JavaScript can you help me?
In dropdownlist I use data from dataSet - from sql dataBase - this dynamic
list.
 
Try this...

<HTML>
<script language="javascript">
function myCB_CheckedChanged()
{
if (document.getElementById("myCB").checked == true)
document.getElementById("myDDL").disabled = false;
else
document.getElementById("myDDL").disabled = true;
}
</script>
<body>
<form id="Form1" method="post" runat="server">
<asp:CheckBox id="myCB" onclick="myCB_CheckedChanged();" runat="server"
Text="My Check Box" Checked=True />
<br>
<asp:DropDownList id="myDDL" runat="server"/>
</form>
</body>
</HTML>
 
Try this...

<HTML>
<script language="javascript">
function myCB_CheckedChanged()
{
if (document.getElementById("myCB").checked == true)
document.getElementById("myDDL").disabled = false;
else
document.getElementById("myDDL").disabled = true;
}
</script>
<body>
<form id="Form1" method="post" runat="server">
<asp:CheckBox id="myCB" onclick="myCB_CheckedChanged();" runat="server"
Text="My Check Box" Checked=True />
<br>
<asp:DropDownList id="myDDL" runat="server"/>
</form>
</body>
</HTML>
 
Try this...

<script language="javascript">
function myCB_CheckedChanged()
{
if (document.getElementById("myCB").checked == true)
document.getElementById("myDDL").disabled = false;
else
document.getElementById("myDDL").disabled = true;
}
</script>
<body>
<form id="Form1" method="post" runat="server">
<asp:CheckBox id="myCB" onclick="myCB_CheckedChanged();" runat="server"
Text="My Check Box" Checked="True" />
<br>
<asp:DropDownList id="myDDL" runat="server" />
</form>
</body>
 
Sorry about the multiple messages, first few responded saying that they were
unsuccessfully sent.
 
ASP.NET is a server side technology. You want to do something on client
side. For this you can just write some javascripts in your aspx file as if
it is a regular html file. All you need to know is what html controls will
represent your server controls on the client. A checkbox will become an
<input type=checkbox> and a ddl will turn into a <select>.

Eliyahu
 
Back
Top