Adding Attribute to BUTTON postback?

  • Thread starter Thread starter darrel
  • Start date Start date
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
 
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)
 
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
 
Back
Top