473,399 Members | 4,192 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Hook JScript Client Events to Server Controls

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>
Nov 18 '05 #1
1 1637
2 options:
1) chkBoxProduct.Attributes.Add("OnClick", "testFunction(this);")
2) chkBoxProduct.Attributes.Add("OnClick",
"testFunction("+chkBoxProduct.ClientId+");")
"David Pifer via .NET 247" <an*******@dotnet247.com> wrote in message
news:em*************@TK2MSFTNGP10.phx.gbl...
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>
Nov 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: Harag | last post by:
Hi All. I'm stating out doing some web developing. I was wondering which of the server side languages should I concentrate on and learn. I Know CSS, HTML, T-SQL I can look at the client...
1
by: Matthew Louden | last post by:
Personally, I am totally confused with the following control terms and usage and advantages of each one in ASP.NET web application. Here's what I know so far.. 1. HTML Client Control: understood...
5
by: Mong | last post by:
Hi, I have a webform with various asp controls on it such as textboxes and dropdownlists. I'm fairly new to asp.net coming from VB6 and am wondering when it's best to use client side events and...
3
by: Larry David | last post by:
Hi, I'm just trying to wrap my mind around the ASP.NET model. Let me walk you through a trivial scenario: Let's say I have a form containing a text box where the user enters his name. It also...
10
by: SergioT | last post by:
Hi I wanna to create a jscript function that sets the value of a textbox into a datagrid, But the problem is How can I obtain the name of the textbox and send it to my jscript function???? The...
9
by: WRH | last post by:
Hello I am new to asp but I made some Jscript functions which work fine. The functions contain some strings used as a registration key for some apps. It is important that these strings not be...
2
by: Mike | last post by:
Hi, I am strugling with a simple problem which I can't seem to resolve. I have an asp.net page which contains a server-control (flytreeview, which is a kind of a tree to be exact). The tree is...
10
by: Ben | last post by:
Hi, I made an application in classic asp (reservation of books and video stuffs for students) and want to migrate to asp.net. The user has to chose a date, then pushung on a submit button. The...
0
by: zeng.hui.stephen | last post by:
I download the demo http://msdn.microsoft.com/msdnmag/issues/02/10/cuttingedge/. I inherite the demo, and write my code. I want to use Hook to monitor C++ Edit change. I use a C# form...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.