Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Hook JScript Client Events to Server Controls

Reply
Thread Tools

Hook JScript Client Events to Server Controls

 
 
David Pifer via .NET 247
Guest
Posts: n/a
 
      05-02-2004
Hello,

Fooling around with ASP.Net and wanted to know if this ispossible...I wanted to attach a client event to a ASP:Checkboxcontrol. I got this to work by adding this line of code to theSub Page_Load

Code:
chkBoxProduct.Attributes.Add("OnClick", "testFunction();")

This function just displays an alert box that says the basic'Hello World!'

That is fine...I got this to work when I ran the WebForm1.aspxpage however, this is what I can not get to work let's say Ichange the JavaScript function that is in between the <HEAD>tags on the HTML page to have a parameter and for simplicitywant to show the name of the checkbox I am checking.

Code:
function testFunction(chkBox)
{
alert(chkBox.Name);
}

Here is the code from the WebForm1.aspx page

Code:
<asp:CheckBox ID="chkBoxProduct" OnClick="testFunction(this)"Runat="server"></asp:CheckBox>

and then I try to do this in the Sub Page_Load

Code:
chkBoxProduct.Attributes.Add("OnClick", "testFunction(chkBox);")

When I run the program and click on the checkbox I get 'chkBox isundefined'. So can I only add attributes to the controls thattake no parameters?

Thanks for the help.
Dave Pifer

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>SAhJiuqd6U+I4dJC5KipHA==</Id>
 
Reply With Quote
 
 
 
 
David Jessee
Guest
Posts: n/a
 
      05-02-2004
2 options:
1) chkBoxProduct.Attributes.Add("OnClick", "testFunction(this);")
2) chkBoxProduct.Attributes.Add("OnClick",
"testFunction("+chkBoxProduct.ClientId+");")


"David Pifer via .NET 247" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
Hello,

Fooling around with ASP.Net and wanted to know if this is possible...I
wanted to attach a client event to a ASP:Checkbox control. I got this to
work by adding this line of code to the Sub Page_Load

Code:
chkBoxProduct.Attributes.Add("OnClick", "testFunction();")

This function just displays an alert box that says the basic 'Hello World!'

That is fine...I got this to work when I ran the WebForm1.aspx page however,
this is what I can not get to work let's say I change the JavaScript
function that is in between the <HEAD> tags on the HTML page to have a
parameter and for simplicity want to show the name of the checkbox I am
checking.

Code:
function testFunction(chkBox)
{
alert(chkBox.Name);
}

Here is the code from the WebForm1.aspx page

Code:
<asp:CheckBox ID="chkBoxProduct" OnClick="testFunction(this)"
Runat="server"></asp:CheckBox>

and then I try to do this in the Sub Page_Load

Code:
chkBoxProduct.Attributes.Add("OnClick", "testFunction(chkBox);")

When I run the program and click on the checkbox I get 'chkBox is
undefined'. So can I only add attributes to the controls that take no
parameters?

Thanks for the help.
Dave Pifer

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>SAhJiuqd6U+I4dJC5KipHA==</Id>


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Hook JScript functions using IActiveScript using C++ Eran Javascript 1 12-31-2006 08:11 PM
What is Server-Side Jscript (not Jscript.NET)? Maxwell2006 ASP .Net 5 03-07-2006 05:28 AM
JScript.Net (JScript 7.0) is official documented language VK Javascript 4 01-12-2006 06:48 PM
Porting from JScript to JScript.Net - compiler error Jon Maz ASP .Net 4 09-09-2004 10:24 AM
Which to Learn: Javascript, Jscript, JScript.NET, ECMA 262 (3rd ed)? John Bentley Javascript 14 02-05-2004 06:14 PM



Advertisments