View Full Version : form action attribute in ASP.NET

12-14-2004, 12:56 AM

I want to use a drop-down list in ASP.NET. When the user hits the go or submit button, I want to send them to another page. I cannot seem to get this to work properly. Here is my code:

<%@ Page Language="C#" %>

<script language="C#" runat="server">

<meta content="Microsoft Visual Studio .NET 7.1" name=GENERATOR>
<meta content=VisualStudio.HTML name=ProgId>
<meta content="Microsoft Visual Studio .NET 7.1" name=Originator>
<LINK href="../bridgeport/main/main.css" type=text/css rel=stylesheet >
<LINK href="../bridgeport/albumpage/album.css" type=text/css rel=stylesheet >
<script src="../bridgeport/main/main.js"></script>

<!--#include file="layout.aspx"-->

<div id="SearchByYear">
<form runat="server" method="post" action="process.aspx">
<asp:dropdownlist id="AlbumDropDown" runat="server">
<input type="submit" value="Submit">



When I use this code and hit the submit button, it does not redirect me
to the "process.aspx page". Instead, it refreshes the same page that the form is on. Any ideas?


12-23-2004, 06:13 PM
Hi Petela

You cannot do that in ASP.NET

Look at this article



12-23-2004, 08:47 PM
yes of course you can

<input type="submit" value="Submit" id="action" />

on the action of your button sub_onClick>>>

you can get the values of your AlbumDropDown

dim dd as string

dd = AlbumDropDown.SelectedIndex.tostring
dd = AlbumDropDown.SelectedValue.tostring

HttpContext.Current.response.Redirect("anyPage.aspx?itemValue=" + dd)

12-23-2004, 10:18 PM
hello gwendaal

I guess I wasn't clear in my answer because I thought it was well explained in the article I added to my previous post.

From the article....

Because ASP.NET handles events in the same Web Form in which they're raised, the form must post back to the same page

in your code...

dim dd as string

dd = AlbumDropDown.SelectedIndex.tostring
dd = AlbumDropDown.SelectedValue.tostring
HttpContext.Current.response.Redirect("anyPage.aspx?itemValue=" + dd)

You got the value of AlbumDropDown.
from a postback to the same page that raised the event(holds the form), not on the processing page.

What you did is then used a Redirect to go to "anyPage.aspx"
by piggybacking the data in a querystring....(GET instead of POST)
which is not the same at all....

although that works, it is not recommended
You might as well go back to ASP 3.0 if you are going to do stuff like that
and code it the old way.

What I am trying to say is that in ASP.NET

this line...
<form runat="server" action="someotherfile.aspx" etc.. />
with runat="server" in it

will not take you directly to someotherfile.aspx.

This is a fundamental change from classic ASP to ASP.NET

and is at the root of the "POSTBACK" concept...


12-24-2004, 07:58 AM
I don't need any article to run asp net applications

no matter as you use asp net ... the main thing is to get what you want

and of course the runat server is everywhere :)
otherwise how can you use a public sub on the action of your button sub_onClick

I thought it was clear

with asp net I am using allways only one page default.aspx
and of course you must redirect to the page itself to get values "?val=5&cat=gallery"

a webform is not a winform and you need get or post

12-29-2004, 06:17 PM
Happy Holidays gwendaal :p


01-04-2005, 09:11 AM
happy new year allison :-)

01-07-2005, 05:07 PM
Thank you both for your help - and Happy New Year. I have learned a little about ASP.NET since I posted my message last month. I know that the page posts back to itself upon submittal. I wanted to show the information submitted in the form - but not the form itself - at postback. The way to do this is to render the form invisible at postback, so that only the content of the form is displayed. The way to do this is to set the form's visible property to false:

protected void Page_Load(object source, EventArgs e)
if (IsPostBack)
PhotoForm.Visible = false;

ThumbnailPhotoMessage.Style.Add("color", "#4682B4");
ThumbnailPhotoMessage.Style.Add("font-weight", "bold");

Thanks again,