Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JavaScript in ASP.NET!

Status
Not open for further replies.

z07924

IS-IT--Management
Feb 18, 2002
122
0
0
GB
I have added a text box called "Email" and also I have two different check boxes are there. It is called supervisor and users. If I click the supervisor check box, I just want to add a email id in the text box. If I click the second users check box, I want to add multiple email ids on the text box. If I click the supervisor check box, it is just want to clear the email id on text box that are specific to supervisor check box.

I am using C#.NET. My code is given below.

private void chklistSupervisor_Changed(object sender, System.EventArgs e)
{
if(chklistSupervisor.Checked)
{
txtEmail.Text = "" + Session["gEmailID"] + "";
}
else
txtEmail.Text = "";
}

private void chklistUser_Changed(object sender, System.EventArgs e)
{
if(chklistUser.Checked)
{
txtEmail.Text = "" + Session["gEmailID"] + ";" + Session["gUserEmailID"] + "" ;
}
else
txtEmail.Text = "";

}

Since I have added some code in the check box change event, It doesn't work properly. It gives some problem when i click the check box.

I just want to change the above code to work using Javascript. so I have to write a JavaScript for that.
Can anyone give any ideas on this.

I would highly appriciate any help.

Thanks in Advance.
 
First of all, the code has some typos in it:
Code:
private void chklistSupervisor_Changed(object sender, System.EventArgs e)
{            
 if(chklistSupervisor.Checked)
 {
  txtEmail.Text = Session["gEmailID"].ToString();
 }
 else
 {
  txtEmail.Text = "";             
 }
}

private void chklistUser_Changed(object sender, System.EventArgs e)
{            
 if(chklistUser.Checked)
 {
  txtEmail.Text = Session["gEmailID"].ToString() + ";" + Session["gUserEmailID"];
 }
 else 
  txtEmail.Text = "";            
 }
}
Second, there is no &quot;oncheck&quot; client side event for a checkbox, so if you just added a javascript event handler in your HTML, i.e. <asp:checkbox onchange=&quot;jsFunction&quot; />, it won't work. Here is how you add it:
Code:
in code behind:
private void Page_Load(object sender, System.EventArgs e)
{
 if(chklistSupervisor.Attributes[&quot;onclick&quot;]==null)
 {
   chklistSupervisor.Attributes.Add(&quot;onclick&quot;, &quot;javascript:handleSuperviserBox(this)&quot;);
 }
}
in page HTML;
<head>
 <script language=&quot;javascript&quot;>
   function handleSuperviserBox(objCheck){
     if(objCheck.checked){
       //do something
     }
   }
 </script>
</head>
Same for another checkbox. The client side event will fire before it goes to the server side event handler.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top