assigning Submit behavior (event) to a form under a masterpagescenario

J

jake

I could not find any specific discussion on this, so please bear with
me as I am less experienced programming for the web than I am for the
desktop.

I have a master page with a <body> tag such as this (as this is part
of the default content from the horse's mouth);

<body>
<form id="form1" runat="server">
<div>
<asp:ContentPlaceHolder ID="ContentPlaceHolder1"
runat="server">

</asp:ContentPlaceHolder>
</div>
</form>
</body>

This MasterPage serves about 30 pages. Many of the pages have a
submit button which promotes a submit behavior in the displayed page.
I need a few of the "other" pages that share the same MasterPage to
each have a separate onsubmit event handler without having a submit
button. Seeing as to the fact that the ContentPlaceHolder is inside
the <form> tag, I can't simply put an onsubmit="handler()" in the
<form> tag lest I intend it to affect all the pages that share this
MasterPage.

How can I do this without changing the existing setup and potentially
damaging the hundreds of thousands of lines of code that are already
written.

Now, I can, of course, kludge it and bend it to suit my needs, but is
there an elegant way?

Thanks,
jake
 
V

vanderghast

With WPF? either using a style (not recommended, because styles are
generally 'thought' as involving presentation rather than functionality)
where unknown specs are simply disregarded, or register the event for a
particular class:

to register:

EventHandler.RegisterClassHandler( typeof( Button ) , Button.ClickEvent,
new RoutedEventHandler( toto ) ) ;

and to handle the event (has to be static) :

private static void toto( Object sender, RoutedEventArgs e )
{
System.Media.SystemSounds.Beep.Play( );
// e.Handled = true;
}



I have never used that technique, though. Just saw it, among other places,
in "WPF in Action with Visual Studio 2008", at Manning, by Feldman and
Daymon.


Vanderghast, Access MVP
 
J

jake

With WPF?  either using a style (not recommended, because styles are
generally 'thought' as involving presentation rather than functionality)
where unknown specs are simply disregarded, or register the event for a
particular class:

to register:

    EventHandler.RegisterClassHandler( typeof( Button ) , Button.ClickEvent,
new RoutedEventHandler( toto ) ) ;

and to handle the event (has to be static) :

    private static void toto( Object sender, RoutedEventArgs e )
    {
        System.Media.SystemSounds.Beep.Play( );
        // e.Handled = true;
    }

I have never used that technique, though. Just saw it, among other places,
in "WPF in Action with Visual Studio 2008", at Manning, by Feldman and
Daymon.

Vanderghast, Access MVP

Thanks vanderghast,
Actually, it is not with WPF. But you gave me an idea. And I am
rather embarrassed I did not think of it; and that is to have the code
behind that particular page itself register the event handler. Thanks
a great deal.
jake
 
J

jake

Thanks vanderghast,
Actually, it is not with WPF.  But you gave me an idea.  And I am
rather embarrassed I did not think of it; and that is to have the code
behind that particular page itself register the event handler.  Thanks
a great deal.
jake

For the record, the following worked;

I added an id for the <form> tag on the MasterPage, say "mainForm".
Then in the PageLoad event handler of the specific page I added the
following;

object mpForm = Master.FindControl("mainForm");
((HtmlForm)mpForm).Attributes.Add("onsubmit", "handler()");
 

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

Top