473,394 Members | 1,829 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,394 software developers and data experts.

Adding ajax/som event handler programmatically

I wrote an event handler with
Sys.UI.DomEvent.addHandler($get("MyButton"),"click ",myfunc);

function myfunc(event)

{

alert("Hi!");

}

1.) If I write this code as a javascript block after the page under the
closing </htmltag everything works fine.

2.) If I write this code as a javascript block between the <headtags I get
an null pointer error from $get("MyButton").

3.) I get the same error if I use the ScriptManager.Scripts.Add(Reference),
obviously because the button "MyButton" doesn't exist yet.

So how can I add my event handler programmatically to achive the same
effect as in 1.)?

Regards

R4DIUM

Jan 27 '08 #1
3 2741
Howdy,

Leave the function declaration as it is, and paste this to Page_Load, or
Page_PreRender event handler:

string script = String.Format(
"Sys.UI.DomEvent.addHandler($get('{0}'),'click',my func);",
btn.ClientID);

ClientScript.RegisterStartupScript(this.GetType(), "whatever",
script, true);

Regards
--
Milosz
"news.rz.uni-karlsruhe.de" wrote:
I wrote an event handler with
Sys.UI.DomEvent.addHandler($get("MyButton"),"click ",myfunc);

function myfunc(event)

{

alert("Hi!");

}

1.) If I write this code as a javascript block after the page under the
closing </htmltag everything works fine.

2.) If I write this code as a javascript block between the <headtags I get
an null pointer error from $get("MyButton").

3.) I get the same error if I use the ScriptManager.Scripts.Add(Reference),
obviously because the button "MyButton" doesn't exist yet.

So how can I add my event handler programmatically to achive the same
effect as in 1.)?

Regards

R4DIUM

Jan 27 '08 #2
Thx - where exactly do I register the js-file which contains my "myfunc" ?

Regards

R4DIUM
"Milosz Skalecki [MCAD]" <mi*****@DONTLIKESPAMwp.plschrieb im Newsbeitrag
news:D4**********************************@microsof t.com...
Howdy,

Leave the function declaration as it is, and paste this to Page_Load, or
Page_PreRender event handler:

string script = String.Format(
"Sys.UI.DomEvent.addHandler($get('{0}'),'click',my func);",
btn.ClientID);

ClientScript.RegisterStartupScript(this.GetType(), "whatever",
script, true);

Regards
--
Milosz
"news.rz.uni-karlsruhe.de" wrote:
>I wrote an event handler with
Sys.UI.DomEvent.addHandler($get("MyButton"),"clic k",myfunc);

function myfunc(event)

{

alert("Hi!");

}

1.) If I write this code as a javascript block after the page under the
closing </htmltag everything works fine.

2.) If I write this code as a javascript block between the <headtags I
get
an null pointer error from $get("MyButton").

3.) I get the same error if I use the
ScriptManager.Scripts.Add(Reference),
obviously because the button "MyButton" doesn't exist yet.

So how can I add my event handler programmatically to achive the same
effect as in 1.)?

Regards

R4DIUM


Jan 27 '08 #3
Is there a possibility to have the
Sys.UI.DomEvent.addHandler($get('ButtonID'),'click ',myfunc) in a file as
well?

Regards

RADIUM

"Axel Gallus" <uh**@rz.uni-karlsruhe.deschrieb im Newsbeitrag
news:fn**********@news2.rz.uni-karlsruhe.de...
Thx - where exactly do I register the js-file which contains my "myfunc" ?

Regards

R4DIUM
"Milosz Skalecki [MCAD]" <mi*****@DONTLIKESPAMwp.plschrieb im
Newsbeitrag news:D4**********************************@microsof t.com...
>Howdy,

Leave the function declaration as it is, and paste this to Page_Load, or
Page_PreRender event handler:

string script = String.Format(
"Sys.UI.DomEvent.addHandler($get('{0}'),'click',my func);",
btn.ClientID);

ClientScript.RegisterStartupScript(this.GetType(), "whatever",
script, true);

Regards
--
Milosz
"news.rz.uni-karlsruhe.de" wrote:
>>I wrote an event handler with
Sys.UI.DomEvent.addHandler($get("MyButton"),"cli ck",myfunc);

function myfunc(event)

{

alert("Hi!");

}

1.) If I write this code as a javascript block after the page under the
closing </htmltag everything works fine.

2.) If I write this code as a javascript block between the <headtags I
get
an null pointer error from $get("MyButton").

3.) I get the same error if I use the
ScriptManager.Scripts.Add(Reference),
obviously because the button "MyButton" doesn't exist yet.

So how can I add my event handler programmatically to achive the same
effect as in 1.)?

Regards

R4DIUM



Jan 27 '08 #4

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

Similar topics

3
by: Clarence Gardner | last post by:
I'm seeing surprising behavior, consistent across Opera, Firefox, and IE. An event handler is changing the value of an element, and there is apparently no Change event being generated for the...
3
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that...
2
by: Tim Marsden | last post by:
Hi, This is what I am doing, please comment if this is the correct way. I need to add controls to a form dynamically. Within the Page_Load event (is not Postback) I run a routine to create the...
0
by: Kurt | last post by:
Hi Brent, I don't know if this is best practices per se`, but it works. The following generates a new button control each time menu item 1 is clicked and assigns an event handler to it. ...
9
by: Neo Geshel | last post by:
I have strip-mined, strip-searched, and completely exhausted the Internet (up to the 30th page on Google, with 100 results per page!!), all without finding an answer to my question AS TO WHY IT...
15
by: Oleg Subachev | last post by:
I need to programmatically invoke from other class Click event of the Button on my Form. Button.OnClick method is protected, not public. How to perform this ? Oleg Subachev
4
by: Bob | last post by:
Hi, I'm working with VWD and i defined programmatically a button (in code-behind) with an ID. So I expect to see beside "Page Events" and "Form1" my button "b1" in order to use the Click event....
2
by: ChrisCicc | last post by:
Hi All, I got a real doozy here. I have read hundreds upon hundreds of forum posts and found numerous others who have replicated this problem, but have yet to find a solution. Through testing I have...
6
by: SAL | last post by:
hello, I'm using a radiobuttonlist in an updatepanel in an item template in a Gridview control. I'm populating the radiobuttonlist in the RowDataBound event. I have the control toolkit registered...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.