Dynamic Javascript in ASP button

W

Wayne Sepega

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(this, 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
 
B

bruce barker \(sqlwork.com\)

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)
 
W

Wayne Sepega

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
 
W

Wayne Sepega

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top