Adding Attribute to BUTTON postback?

D

darrel

I am using a javascript WYSIWYG text editor for our CMS. To grab the proper
content we need to add a javacsript call to the form:

Form1.Attributes.Add("onSubmit", "myOnSubmitEventHandler();")

That works fine.

However, we also have some dropDownLists that trigger a postback. If we
change these, I still need to update the text editor, so I added attributes
to them:

ddl_customContent.Attributes.Add("onChange", "myOnSubmitEventHandler();")
ddl_permissions_primaryCategory.Attributes.Add("onChange",
"myOnSubmitEventHandler();")

Again, that's working just fine.

The catch...I now have a few additional Buttons that trigger postbacks.
However, I can't figure out how to apply the same attribute to these
particular functions. They seem to ignore the 'onSubmit' attribute of the
form. Does that make sense?

I tried adding an onClick event, but that, too, doesn't seem to behave the
same way as the onChange event.

Thoughts?

-Darrel
 
B

bruce barker \(sqlwork.com\)

the form onsubmit is only called if the browser posts (say from enter or
submit button). if javascript does the postback (form.submit()) as done by
the autopostback controls then it won't fire. this is why you need add to
the dropdown.

generally asp:button are rendered as a submit, and will call the onsubmit.
they have a onclick event that fires before the postback. view source to see
if your onclick attributes are rendered correctly

-- bruce (sqlwork.com)
 
D

darrel

generally asp:button are rendered as a submit, and will call the onsubmit.
they have a onclick event that fires before the postback. view source to
see if your onclick attributes are rendered correctly

After MUCH digging, I finally discovered the issue wasn't with the onClick
at all.

If anyone cares, the issue is that the javascript was grabbing data from an
form field that was sometimes set to DISPLAY: hidden in the CSS. Apparently
javascript can't grab that. ;o)

So, instead of hiding it via css, I know move it off-screen via css, where
javascript CAN 'see' it.

Less accessible, but seems to work.

-Darrel
 

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
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top