Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx_professional thread: Action Property of a Form


Message #1 by "thinwolf" <liucb@h...> on Mon, 22 Jul 2002 07:17:00
This is a multi-part message in MIME format.

------=_NextPart_000_0010_01C2310E.08E3B880
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: 7bit

I just posted our findings on this last week. Here's the content of that
posting:

 

Well, this may not be what you are looking for but is a related bug in
ASP.NET that we were credited with finding. I'll share it just in case
it is one of your difficulties. Many Web hosts require that you use
virtual paths instead of file system based paths when referencing
external files, especially SSI. The way to use virtual paths is to
include the HTML/XHTML base tag in your pages. This tag specifies the
root of your Web application and then all paths in your application (at
least on the pages that the base tag is included in) must be relative to
this path.

 

 

 

For instance, if I have a page that uses the base tag as follows:

 

 

 

<base href="http://www.webgeniuses.com" />

 

 

 

then all paths in that page must adhere to this page as the root or they
will be invalid. I normally organize my Web projects into folder
structures such as:

 

 

 

Root

 

-- Controls

 

-- Forms

 

-- Images

 

-- Styles

 

 

 

And so on. Thus, if I'm coding in a page that is located in the Forms
folder and want to reference an image in the Images folder, my img tag
in the page would resemble:

 

 

 

<img src="Images/MyImage.gif" />

 

 

 

Notice that this path comes straight off the root and does not use the
"../" that you might expect with a file based path. Again, this is
required by many Web hosts now who restrict the use of file based paths
for security purposes.

 

 

 

The problem arises in the form tags. In traditional ASP, the action
attribute of the form tag referenced the next ASP page that you would be
posting your form values to. In ASP.NET, however, this paradigm has
changed and all ASP.NET pages are created as self posting pages. If you
want to post results to another page, you must do so in the code behind
page. There are a few ways to do this but the most common is to store
your values to be passed into Session variables and then use
Response.Redirect to post to the next page.

 

 

 

Even so, if you are using the HTML/XHTML base tag, and want to post back
to the same page or create a self posting page and your pages reside in
a sub folder, such as mine do, you will end up with an HTTP 404 error in
ASP.NET. This is because ASP.NET will always overwrite anything you put
in the action attribute of a server side form tag with simply the name
of the current page in an attempt to force it to be a self posting page.

 

 

 

For instance, if I'm using the HTML/XHTML base tag to control my paths,
my action attribute of my form tag would be:

 

 

 

<form action="Forms/MyForm.aspx" method="post" runat="Server></form>

 

 

 

This makes sense with the folder structure and paths, however, since
ASP.NET overwrites this action attribute in every case on a server side
form tag, the page sent to the client will have a form tag of:

 

 

 

<form action="MyForm.aspx" method="post" runat="Server></form>

 

 

 

where MyForm is the name of the current page in both cases. As you can
see, if this page is sitting in the Forms folder and I am using the
HTML/XHTML base tag, this will be pointing to a page sitting in the root
and not in the sub folder and we will receive an HTTP 404 error as soon
as we attempt to submit the form.

 

 

 

This is a confirmed bug in ASP.NET and there is no work around for it
that we have been able to find. We just simply cannot combine ASP.NET,
the base tag, and sub folders. Since you are looking for path options,
you might stumble across this and be perplexed or frustrated like we
were.

 

 

 

However, keep in mind that the base tag affects only client side coding.
Even if you do use an option such as this, your server side paths will
always be in reference to the server's file system.

 

 

-----Original Message-----
From: thinwolf [mailto:liucb@h...] 
Sent: Monday, July 22, 2002 07:17
To: ASPX_Professional
Subject: [aspx_professional] Action Property of a Form

 

When I set the action propery of a server form to the url of another
page 

it still posts to itself

 

it states in the documentation that you can over-ride this behaviour

 

ie 

 

<form runat="server" method="post" action="search.aspx">

FORM ELEMENTS

</form>

 

and I have seen that you had said to remove runat="server"

 

I tried it, it doens't work, it generated an error, the code is:

 

<html>

<head>

  <title>Holiday page</title>

</head>

<body>

  <form action="holidayresponse.aspx" method="post">

    <h1>Feiertag Holidays</h1>

    Please enter your details here.

    <br /><br />

    Name:<asp:textbox id="FullName" runat="server" />

    <br /><br />

    Address:<asp:textbox id="Address" rows="5" textmode="multiline" 

                         runat="server" />

    <br /><br />

    Sex - 

    <asp:radiobuttonlist id="sex" runat="server">

      <asp:listitem value="Male" />

      <asp:listitem value="Female" />

    </asp:radiobuttonlist>

    Please select the destination you would like details on:

    <asp:dropdownlist id="Destination" runat="server">

      <asp:listitem value="Madrid" />

      <asp:listitem value="Barcelona"/>

      <asp:listitem value="Lisbon"/>

      <asp:listitem value="Oslo"/>

      <asp:listitem value="Prague"/>

    </asp:dropdownlist>

    <br /><br />

      <input type="Submit">

    <input type="Reset">

  </form>  

</body>

</html>

 

And the server replies:

 

Server Error in '/' Application.

------------------------------------------------------------------------
--

------

 

Control 'FullName' of type 'TextBox' must be placed inside a form tag 

with runat=server. 

Description: An unhandled exception occurred during the execution of the


current web request. Please review the stack trace for more information 

about the error and where it originated in the code. 

 

Exception Details: System.Web.HttpException: Control 'FullName' of 

type 'TextBox' must be placed inside a form tag with runat=server.

 

Source Error: 

 

An unhandled exception was generated during the execution of the current


web request. Information regarding the origin and location of the 

exception can be identified using the exception stack trace below.  

 

Stack Trace: 

 

 

[HttpException (0x80004005): Control 'FullName' of type 'TextBox' must
be 

placed inside a form tag with runat=server.]

   System.Web.UI.Page.VerifyRenderingInServerForm(Control control) +151

 
System.Web.UI.WebControls.TextBox.AddAttributesToRender(HtmlTextWriter 

writer) +38

   System.Web.UI.WebControls.WebControl.RenderBeginTag(HtmlTextWriter 

writer) +17

   System.Web.UI.WebControls.TextBox.Render(HtmlTextWriter writer) +17

   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +243

   System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +72

   System.Web.UI.Control.Render(HtmlTextWriter writer) +7

   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +243

   System.Web.UI.Page.ProcessRequestMain() +1900

 

 

 







  Return to Index