views:

165

answers:

4

I have 3 ASP.Net pages. Each one has a form, a submit button, and a Javascript submit function, which it validates textbox data.

When I convert these 3 pages to Master Page/Content Page, what is the best way to merge three forms and submit functions?

Thanks in advance!

A: 

You can put the submit function in the master page and make the content pages define per-page functions or variables that the submit function uses.


For more specific advice, please post more details.

SLaks
+1  A: 

Just because multiple pages have forms doesn't mean the form processing logic should be refactored into a master page. In the codebehind of wherever a form is defined is typically the best place for the form processing logic to go.

gWiz
+1  A: 

If they only differ by the contents of the form, then put everything else into the Master page, and the form alone into each Content Page.

I'd leave the Submit method for each form in it's Content page's code-behind, because these will be independent of each other.

You could have them all link to the same javascript validation file, for neatness, and call different validation methods

<asp:ScriptManager ID="ScriptManager1" runat="server">
    <Scripts>
        <asp:ScriptReference Path="Validation.js" />
    </Scripts>
</asp:ScriptManager>

and have each form's Submit button call its own method, e.g.

<asp:Button ID="btnSave" runat="server" OnClientClick="ValidateFormA" OnClick="Save" Text="Save" />
Rafe Lavelle
+1  A: 

I would create a web user control to encapsulate the UI and functionality of the submit button, Javascript submit function, and textbox.

Then you could add the control to a master page if you wanted to.

CRice