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

Dynamic Javascript in ASP button

I have inherited from System.Web.UI.WebControls and overrode the OnRender of
my new button. In the on render I generate some JavaScript and add it as an
attribute as follows:

this.Attributes.Add("onclick", javascript);

I have the following issues:

1) I have to add to the javascript the following:
this.Page.ClientScript.GetPostBackEventReference(t his, null);
When added, this causes the post back to fire even if the client
validation fails. Also the javascript gets both the page reference I added
as well as the PostBackWithOptions.

2) Don't add in GetPostBackEventRefernce
A page with no validation doesn't have the call to the post back,
but if there is client validation then the post back with options gets
generated.
The above issues occur even if I add the javascript to the OnClientClick
event.

I'm fairly new to writing ASP.net controls, so if I am putting/generating
the javascript in the wrong place or missing something obvious please let me
know.

Thanks
Wayne
Aug 30 '06 #1
3 1786
you need to understand submit button and client script. normally, unlike
other asp.net controls, buttons postback with the need of client script as
the browser handles it. if you use validators, the the browsers default
behavior is overridden by attaching client script to the button. this client
script cancels the automatic postback, and calls client script to validate
and conditionally postback. if you add you own client script it must be
compatiable with .nets onclick code. view the souce and see the generated
code and adjust your client code.

-- bruce (sqlwork.com)

"Wayne Sepega" <Me******@community.nospamwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
>I have inherited from System.Web.UI.WebControls and overrode the OnRender
of my new button. In the on render I generate some JavaScript and add it as
an attribute as follows:

this.Attributes.Add("onclick", javascript);

I have the following issues:

1) I have to add to the javascript the following:
this.Page.ClientScript.GetPostBackEventReference(t his, null);
When added, this causes the post back to fire even if the client
validation fails. Also the javascript gets both the page reference I added
as well as the PostBackWithOptions.

2) Don't add in GetPostBackEventRefernce
A page with no validation doesn't have the call to the post back,
but if there is client validation then the post back with options gets
generated.
The above issues occur even if I add the javascript to the OnClientClick
event.

I'm fairly new to writing ASP.net controls, so if I am putting/generating
the javascript in the wrong place or missing something obvious please let
me know.

Thanks
Wayne

Aug 30 '06 #2
I've been doing that, but I've not been able to find a clean way to
determine when I need to append the postback ref to my javascript and when
not too. IF there are validators, then I don't need to append it, if there
are not any validators then I need to append. Also how do I tell if they are
client or server side validators? As I'm not sure if the append or not
append should be tied to just client validators.

Wayne

"bruce barker (sqlwork.com)" <b_*************************@sqlwork.comwrote
in message news:ef**************@TK2MSFTNGP06.phx.gbl...
you need to understand submit button and client script. normally, unlike
other asp.net controls, buttons postback with the need of client script as
the browser handles it. if you use validators, the the browsers default
behavior is overridden by attaching client script to the button. this
client script cancels the automatic postback, and calls client script to
validate and conditionally postback. if you add you own client script it
must be compatiable with .nets onclick code. view the souce and see the
generated code and adjust your client code.

-- bruce (sqlwork.com)

"Wayne Sepega" <Me******@community.nospamwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
>>I have inherited from System.Web.UI.WebControls and overrode the OnRender
of my new button. In the on render I generate some JavaScript and add it
as an attribute as follows:

this.Attributes.Add("onclick", javascript);

I have the following issues:

1) I have to add to the javascript the following:
this.Page.ClientScript.GetPostBackEventReference(t his, null);
When added, this causes the post back to fire even if the client
validation fails. Also the javascript gets both the page reference I
added as well as the PostBackWithOptions.

2) Don't add in GetPostBackEventRefernce
A page with no validation doesn't have the call to the post back,
but if there is client validation then the post back with options gets
generated.
The above issues occur even if I add the javascript to the OnClientClick
event.

I'm fairly new to writing ASP.net controls, so if I am putting/generating
the javascript in the wrong place or missing something obvious please let
me know.

Thanks
Wayne


Aug 30 '06 #3
I've been doing that, but I've not been able to find a clean way to
determine when I need to append the postback ref to my javascript and when
not too. IF there are validators, then I don't need to append it, if there
are not any validators then I need to append. Also how do I tell if they are
client or server side validators? As I'm not sure if the append or not
append should be tied to just client validators.

Wayne

"bruce barker (sqlwork.com)" <b_*************************@sqlwork.comwrote
in message news:ef**************@TK2MSFTNGP06.phx.gbl...
you need to understand submit button and client script. normally, unlike
other asp.net controls, buttons postback with the need of client script as
the browser handles it. if you use validators, the the browsers default
behavior is overridden by attaching client script to the button. this
client script cancels the automatic postback, and calls client script to
validate and conditionally postback. if you add you own client script it
must be compatiable with .nets onclick code. view the souce and see the
generated code and adjust your client code.

-- bruce (sqlwork.com)

"Wayne Sepega" <Me******@community.nospamwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
>>I have inherited from System.Web.UI.WebControls and overrode the OnRender
of my new button. In the on render I generate some JavaScript and add it
as an attribute as follows:

this.Attributes.Add("onclick", javascript);

I have the following issues:

1) I have to add to the javascript the following:
this.Page.ClientScript.GetPostBackEventReference(t his, null);
When added, this causes the post back to fire even if the client
validation fails. Also the javascript gets both the page reference I
added as well as the PostBackWithOptions.

2) Don't add in GetPostBackEventRefernce
A page with no validation doesn't have the call to the post back,
but if there is client validation then the post back with options gets
generated.
The above issues occur even if I add the javascript to the OnClientClick
event.

I'm fairly new to writing ASP.net controls, so if I am putting/generating
the javascript in the wrong place or missing something obvious please let
me know.

Thanks
Wayne



Aug 30 '06 #4

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

Similar topics

13
by: mr_burns | last post by:
hi, is it possible to change the contents of a combo box when the contents of another are changed. for example, if i had a combo box called garments containing shirts, trousers and hats, when...
4
by: pizzy | last post by:
INTRO: I tried to clean it up for easy reading. I hope I didn't make any mistakes. PROBLEM: WOW, this is some crazy sh!t. I can't get my checkbox (see "TAGSELECTED") to print my textboxes (see...
1
by: kusanagihk | last post by:
To all, I'm working on a javascript to dynamic build a common set of HTML controls. 01) I've used the DOM object to build a <div> tag; then build 1 <input type='button'/> and 1 <input...
1
by: nsvmani | last post by:
Hi, i am trying to get the FileOpen dialogue window as soon as clicked href link I am using IE6 with ActiveX enabled. Just need to get the File Open dialogue window when i click on the HREF links.It...
3
polymorphic
by: polymorphic | last post by:
I have succeeded in embedding PDF files in a dynamic iframe. The problem is that I need the PDF to cache. If the PDF remains the same from page load to page load then the pdf is somehow cached with...
0
bmallett
by: bmallett | last post by:
First off, i would like to thank everyone for any and all help with this. That being said, I am having a problem retrieving/posting my dynamic form data. I have a form that has multiple options...
5
by: plsHelpMe | last post by:
How to create dynamic javascript arrays using dojo toolkits Hello frens, I am in a big trouble. My objective is: I am having some categories shown by differnent radio buttons, on the click of...
1
by: cdmsenthil | last post by:
I have an Infragistics UltrawebGrid . Each Row in the grid is attached to a context menu using Infragistics CSOM Upon click on the menu, I am creating an Iframe dynamically which points to...
3
by: azegurb | last post by:
hi I have just took from internet dinamic table. this table is dynamic and its rows dynamically can be increased. but i would like how create SUM function that automatically sums each added row...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...

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.