By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,300 Members | 1,795 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,300 IT Pros & Developers. It's quick & easy.

Adding ajax/som event handler programmatically

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.