1
votes

I have read the other results, but nothing specific to my issue.

I realize having two form tags with runat="server" does not work. My problem is that I require a form in the Master Page file to handle the menus and such, and the 'child' page of my application also requires a form tag to handle its operations.

I have tried to remove the form tag in my 'child' pages, but the code-behind doesn't see that I am using the form tag in the Master Page. Due to this, compilation fails ("The name 'form1' does not exist in the current context")

How can I attain the goal of keeping my menus in the Master Page working, while keeping my 'child' pages from erroring out when compiling?

1
Can you post the form code?Stanley Cup Phil

1 Answers

4
votes

If you go the route of removing all the form tags from all the child pages (which I would suggest), you can add a reference to the Master Page's Form tag as a property that can be accessed by the child pages. Here would be the Master Page code behind:

public HtmlForm form1 {
    get { return this.form1; }
}

Then you could reference from the child page:

public void MyMethod() {
    HtmlForm theForm = ((MyMasterPageType)this.Master).form1;
    theForm.Controls.Add(...);
}

And if you set the MasterPageType in the child pages, you can reference directory with this.Master.form1 (add this to the markup page of the child page):

<%@ MasterType TypeName="MyMasterPageType" %>