Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 20th, 2007, 09:21 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

If your search entry is simply redirecting to the results page you can put it in place of the iframe. Yes, ASP.NET only uses 1 form, but this is usually not a problem because you are working with postback controls and redirecting to another page (versus) posting to the other page like you would in classic ASP.

-Peter
 
Old July 20th, 2007, 09:46 AM
Authorized User
 
Join Date: Jul 2007
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to u2clone
Default

Tired of me yet?

OK, when I pull the runat="server" out of the page form tag it works, but is that going to mess with the Master Page stuff and all?

When I pull the runat="server" on the search form tag I get a nasty error:

Invalid postback or callback argument. Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.

I have poked around looking for how to put mutliple forms on a page, but they don't seem to make sense unless I am looking for the wrong thing.

I hope to be out of your hair on this soon.

 
Old July 20th, 2007, 10:45 AM
Authorized User
 
Join Date: Jul 2007
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to u2clone
Default

I should mention that I am having to removed the runat-"server" from the form tag on the MasterPage to make it work.

So far I can't tell any issues, is this a fair method to make the form situation work or is there a better way?

 
Old July 20th, 2007, 01:51 PM
Authorized User
 
Join Date: Jul 2007
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to u2clone
Default

OK, now I am confused. The search works locally, but doesnt' work when I post it live. All I did was switch the connection string to the DB on the web. The Response.Redirect doesn't send the user to the page, rather leaving it there and adding a really odd query string at the end in which I have no clue where it came from.

Here is the CPC it is in:

<asp:Content ID="Content1" ContentPlaceHolderID="LeftSide" Runat="Server">

                    <td width="212" valign="top" align="right" style="border-right: #662c5c 1px dashed; padding-right: 2px; padding-left: 2px;">
                    <table width="208" align="center" cellpadding="0" cellspacing="0">
                        <tr>
                            <td><img src="images/search_top.jpg" /></td>
                        </tr>
                        <tr>
                            <td valign="top" style="background-image: url(images/side_grad.jpg); padding-right: 4px; padding-left: 4px; font-size: 9pt; font-family: 'Copperplate Gothic Light', arial, verdana; text-decoration: none;">

                                <form id="Form2" runat="server">
                                Country:<br />
                                <asp:DropDownList ID="Country_Select" runat="server" Width="160px" ></asp:DropDownList>
                                <br />
                                State: (if Country is NOT the US select <b>'None'</b>; if the US please select a state)<br />
                                <asp:DropDownList ID="State_Select" runat="server" DataSourceID="SqlDataSource2" DataTextField="State" DataValueField="StateID" Width="160px"></asp:DropDownList>
                                <br />
                                Price Range:<br />
                                <asp:DropDownList ID="Price_Select" runat="server" DataSourceID="SqlDataSource3" DataTextField="PriceRange" DataValueField="PriceID" Font-Names="arial" Font-Size="9pt" Font-Bold="true" Width="160px"></asp:DropDownList>
                                <br /><br />
                                <asp:Button ID="Button1" runat="server" Width="151px" Text="Find My Home" Font-Size="9pt" Font-Names="'Copperplate Gothic Light', arial, verdana" OnClick="SearchTest" />
                                </form>

    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:LuxLife %>"
        SelectCommand="SELECT * FROM [Lux_Country]"></asp:SqlDataSource>
    <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:LuxLife %>"
        SelectCommand="SELECT * FROM [Lux_States]"></asp:SqlDataSource>
    <asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:LuxLife %>"
        SelectCommand="SELECT * FROM [Lux_Price]"></asp:SqlDataSource>


                                <p align="center" class="title">Featured Lux-Listings</p>
                            </td>
                        </tr>
                    </table>
                    </td>

</asp:Content>

and the CodeBehind:

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Country_Select.DataSource = SqlDataSource1;
            Country_Select.DataTextField = "Country";
            Country_Select.DataValueField = "CountryID";
            Country_Select.DataBind();
        }

    }

    protected void SearchTest(object sender, EventArgs e)
    {
        string strNewPage;
        strNewPage = "http://www.luxlifeinternational.com/luxlife/luxlistings/default.aspx?countryid={0}&stateid={1}&priceid={2} ";
        strNewPage = string.Format(strNewPage, Country_Select.SelectedValue, State_Select.SelectedValue, Price_Select.SelectedValue);
        Response.Redirect(strNewPage);

On the redirect, I tried both virtual and hard link and neither worked. Might this have to do with the runat="server" I removed from the MasterPage?

At a loss yet again.

 
Old July 20th, 2007, 10:03 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

In the ASP.NET model, everything lives within a single form. For a standard web form page, the form tag is declared in the ASPX markup. In the case of a master page scenario, it is in the .master markup. User controls NEVER have a form tag, nor do they have any of the main surrounding HTML (html, title, body) because they are always included on a master or standard/content page.

The reason this model works is that (usually) actions performed on the server are triggered by some postback event (button click, dropdownlist item change, etc). Every form input control in the HTML gets sent to the server with each postback. This way the ASP.NET handler can fire off all the events that need to be handled regardless of where the controls live.

You should simply add your drop down lists and search button to a regular page, user control or master page and then handle the event in the button click handler. You should not be adding more form tags otherwise you will make ASP.NET very unhappy as you are finding out.

Why you are getting weird redirect behavior? I don't know. You shouldn't need to put the entire URL in a page redirect. If the page is in the same directory you don't need anything other than the page. If it's in another directory you can use standard back (../) and forward (<dirname>/) references to the destination page. If you want to reference something relative from the application's root you can use this syntax: "~/dir/page.asp". The ~ character gets replaced with the application root (the path of the virtual directory if there is one). This is the simplest way to ensure that your file references will work between various server environments such as development and production.

-Peter
 
Old July 21st, 2007, 08:49 AM
Authorized User
 
Join Date: Jul 2007
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to u2clone
Default

Peter, thanks for the insight. That worked just fine, and it solved the redirecting problem! It now works swimingly!

Thanks for helping a n00b. :) I'm guilty of Id-10-t errors.

Thanks again!






Similar Threads
Thread Thread Starter Forum Replies Last Post
Help for Select SQL Query with date filter pushpa SQL Server DTS 0 February 6th, 2007 10:06 AM
Help with SQL - filter for "today" Insel Haber ASP.NET 2.0 Basics 2 June 28th, 2006 05:15 PM
sql date filter keyvanjan Classic ASP Databases 3 March 8th, 2006 10:17 PM
Add Filter to a query using VB marcin2k Access VBA 2 March 20th, 2005 07:03 AM
using a query to filter forms lizhaskin Access 6 June 10th, 2004 06:50 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.