views:

28

answers:

1

the problem i have is that i have multiple nested master pages:

  • level 1: global (header, footer, login, navigation, etc...)
  • level 2: specific (search pages, account pages, etc...)
  • level 3: the page itself

now, since only one form can have runat=server, i put the form at global page (so i can handle things like login, feedback, etc...).

now with this solution i'd have to also put the for example level 3 (see above) methods, such as search also on the level 1 master page, but this will lead to this page being heavy (for development) with code from all places, even those that are used on a single page only (change email form for example).

is there any way to delegate such methods from the onclick events (for example: ChangeEMail) from level 1 (global masterpage) to level 3 (the single page itself).

to be even more clear: i want to NOT have to have the method ChangeEMail on the global master page code behind, but would like to 'MOVE' it somehow to the only page that will actually use it. the reason why it currently has to be on the global master is that global master has form runat=server and there can be only one of those per aspx page.

this way it will be easier (more logical) to structure the code.

thnx (hope i explained it correctly)

have searched but did not find any general info on handling this case, usualy the answer is: have all the methods on the master page, but i don't like it. so ANY way of moving it to the specific page would be awesome. thnx

edit also part of the same thing... on the other hand - how to access the textbox1.text for example on the content page from master page? any best practice for this?

+2  A: 

If you put the Search button and textbox on the .aspx itself (level 3) the event handler will also go in the page (or its codebehind). It doesn't matter that the form tag is on the global masterpage (level 1)

As for your second question: You can use

var tb = this.FindControl("textbox1") as TextBox;
Arjan Einbu
checking out #1. for #2, no strong typing available? this seems made for a null pointer when somebody changes the name?
b0x0rz
for #1: i am doing this: <asp:LinkButton ID="SignInLinkButton" runat="server" CssClass="SignInLinkButton" TabIndex="3" OnClick="AuthorizeUser">SignIn</asp:LinkButton> and the code: void AuthorizeUser(object sender, EventArgs e) { [...] } but getting an error: CS1061: 'ASP.manage_signin_default_aspx' does not contain a definition for 'AuthorizeUser' and no extension method 'AuthorizeUser' accepting a first argument of type 'ASP.manage_signin_default_aspx' could be found (are you missing a using directive or an assembly reference?)
b0x0rz
this is why i thought it doesn't work on 'level 3' page. not sure what is wrong then...
b0x0rz
ah ok got it - have to make the method PUBLIC! then it works.
b0x0rz
this also makes the second part not so important any more. thnx a lot for the help :)
b0x0rz