Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
Billkamm
Posting Yak Master
124 Posts |
Posted - 2006-02-03 : 13:52:04
|
I created an ASP web control button on my web form and I did the following line of code:btnSave.Attributes.Add("onclick", "blur();")The problem is that when ASP.Net creates the HTML control on the client side there is already and onclick event (for validation) and this overrides the functionality of my custom onclick event. Is there a way I can prepend additional attributes to the onclick event in this case? |
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2006-02-03 : 14:54:24
|
The question is -- do you still want the postback or do you want your event to fire BEFORE (and in addition to) the post back? |
 |
|
Billkamm
Posting Yak Master
124 Posts |
Posted - 2006-02-03 : 15:26:27
|
Before and in addition to the post back |
 |
|
jsmith8858
Dr. Cross Join
7423 Posts |
|
Billkamm
Posting Yak Master
124 Posts |
Posted - 2006-02-03 : 15:44:26
|
It creates a second onclick event in the resulting HTML. It has the onclick event to process the postback and then the onclick to process blur().The problem is it processes the postback onclick event first and never gets to the blur.I'll read that article and see if I can find anything helpful |
 |
|
Billkamm
Posting Yak Master
124 Posts |
Posted - 2006-03-01 : 15:25:03
|
jsmith8858: I read that article and I found the answer to my solution. When using and HtmlInputButton you cannot end your onclick statement in a semicolon.My code was:onclick="blur();"That did not work, but the following code does work:onclick="blur()"Such minor little details can be so frustrating at times. |
 |
|
DustinMichaels
Constraint Violating Yak Guru
464 Posts |
Posted - 2006-03-01 : 15:33:56
|
Just use external Javascript. Theres no need to have it inline.if(document.getElementById) window.load = load;function load(){ if(document.getElementById("<your button id>") != null) document.getElementById("<your button id>").onclick = someFunction;}function someFunction(){ //javascript to call when button is clicked.} |
 |
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2006-03-01 : 15:57:11
|
quote: Originally posted by BillkammSuch minor little details can be so frustrating at times.
Welcome to the world of computer programming ... it's all about the details. The computer has a nasty habit of doing exactly what we tell it to do, not what we *want* it to do. |
 |
|
Billkamm
Posting Yak Master
124 Posts |
Posted - 2006-03-01 : 16:06:54
|
DustinMichaels: I'm not seeing the benefit of typing in all that extra code when you can just include inline onclick="somefunction()"What is the benefit of adding the onclick attribute dynamically on window load? |
 |
|
|
|
|