Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    Jan 2003
    Posts
    65
    Thanks
    0
    Thanked 0 Times in 0 Posts

    form action attribute in ASP.NET

    Hi,

    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#" %>

    <HTML>
    <HEAD>
    <title></title>
    <script language="C#" runat="server">
    </script>

    <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>
    </HEAD>
    <body>

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

    <div id="SearchByYear">
    <form runat="server" method="post" action="process.aspx">
    <asp:dropdownlist id="AlbumDropDown" runat="server">
    <asp:ListItem>2003</asp:ListItem>
    <asp:ListItem>2002</asp:ListItem>
    <asp:ListItem>2001</asp:ListItem>
    <asp:ListItem>2000</asp:ListItem>
    <asp:ListItem>1999</asp:ListItem>
    <asp:ListItem>1998</asp:ListItem>
    <asp:ListItem>1997</asp:ListItem>
    </asp:dropdownlist>
    <input type="submit" value="Submit">
    </FORM></DIV>


    </body>
    </HTML>

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

    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?

    Thanks,
    petela

  • #2
    New Coder
    Join Date
    Aug 2002
    Posts
    31
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi Petela

    You cannot do that in ASP.NET

    Look at this article

    http://www.macromedia.com/devnet/mx/...ebform_05.html

    allison

  • #3
    Regular Coder
    Join Date
    Jul 2004
    Location
    France
    Posts
    141
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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
    or
    dd = AlbumDropDown.SelectedValue.tostring

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

  • #4
    New Coder
    Join Date
    Aug 2002
    Posts
    31
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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...
    Code:
    dim dd as string
    
    dd = AlbumDropDown.SelectedIndex.tostring
    or
    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...


    allison
    Last edited by allison; 12-23-2004 at 10:39 PM.

  • #5
    Regular Coder
    Join Date
    Jul 2004
    Location
    France
    Posts
    141
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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
    Last edited by gwendaal; 12-24-2004 at 10:11 AM.

  • #6
    New Coder
    Join Date
    Aug 2002
    Posts
    31
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Happy Holidays gwendaal

    allison

  • #7
    Regular Coder
    Join Date
    Jul 2004
    Location
    France
    Posts
    141
    Thanks
    0
    Thanked 0 Times in 0 Posts
    happy new year allison :-)

  • #8
    New Coder
    Join Date
    Jan 2003
    Posts
    65
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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,
    petela


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •