SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a web part embedded in a publishing site that needs to get a reference to the <form runat="server"/> in the master page.

I have to set the 'action' attribute to allow the form to post outside of the site.

Instead of trying every combination of this.Page.Master and this.Parent.Page.Master - I wonder if someone has accomplished this?

Currently I have:

System.Web.UI.HtmlControls.HtmlForm form = (System.Web.UI.HtmlControls.HtmlForm)this.Parent.Page.Master.FindControl("aspnetForm");

But this doesn't work.

share|improve this question
up vote 1 down vote accepted

Did you try:

System.Web.UI.HtmlControls.HtmlForm form = Page.Form;

worked for me.

share|improve this answer
Of course! Perfect, thanks. Much easier than trying to navigate through the SP object hierarchy. – ScottE Dec 13 '11 at 21:15
Well, the find control part works, but the settings of the form action doesn't seem to work. This is definitely possible in .net 3.5, and I tried this exact thing in webforms outside of sharepoint. Does sharepoint prevent this? – ScottE Dec 13 '11 at 21:19
Yes, that's SharePoint specific. Until today I haven't found a workaround for that behavior. – Sig Weber Dec 13 '11 at 22:08
PostBackUrl didn't seem to work either. Oh, Sharepoint, always trying to complicate things. I guess javascript is the only solution here. – ScottE Dec 14 '11 at 13:59

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.