Parser Error Message: Server tags cannot contain <% ... %> constructs.

N

Neil Zanella

Hello,

I would like to do the following:

<form method="post"
action="<%= Request.ServerVariables["URL"] %>"
runat="server">

The reason I would like to do this is twofold:

1. I want my page to be such that when I post I get
rid of the query string appended at the end of the URL.

2. I want my code to be such that when I rename the file that
containins it I don't have to change the name of the .aspx
file in all enclosed action fields.

In PHP, this would have been possible using the PHP_SELF variable.
However, when using ASP.NET, IIS issues the following error message,
which is unfortunate (should I say stupid, given that PHP can do it):

Parser Error Message: Server tags cannot contain <% ... %> constructs.

I wonder why ASP.NET would impose this restriction, and wonder if there
is a workaround for this problem in ASP.NET.

Suggestions welcome,

Best Regards,

Neil
 
P

Philip Q [MVP]

The reason is because you are declaring your form to be an ASP.NET form, and
so ASP.NET manages the postback and form submission process (which is the
prefered way).
However, to do it the way that you are proposing, remove the runat="server"
attribute from the <form> tag.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top