Wrox Programmer Forums
|
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 November 9th, 2006, 07:11 AM
Authorized User
 
Join Date: Mar 2005
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default Post to Another Page problem

Hi Everyone, I wonder if anyone can help me with this problem. I have set up a page called "Default.aspx" that contains a search text box called txtName and a button. I want to post the results of the text search on a another page called searchResults. The results are based on a search by potential students for courses. However when I try to access the page I get an error thrown up as such.

Could not find control 'txtName' in ControlParameter 'Course'.

The page will work perfectly if I post it back to itself but when I post to another page the above error appears. This leads me to suspect that the page is not remembering a value for txtName on the previous. I have tried various incarnations of retrieving the textbox value but to no avail.
I have imported

Code:
<%@ PreviousPageType VirtualPath="~/Default.aspx" %>
and used it with

Code:
    public void Page_Load(object sender, EventArgs e)
    {

        if (PreviousPage != null && PreviousPage.IsCrossPagePostBack)
        {
           TextBox txtName = (TextBox)Page.PreviousPage.FindControl("txtName");
           GridView1.Visible = true;
        }


    }


Nothing seems to work and this one error has gridlocked me at work for 2 days now. Anyways here is a full listing of the code.

default.aspx

Code:
<%@ Register TagPrefix="BIE" TagName="header" Src="header.ascx" %>
<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
    <link rel="stylesheet" href="stylecss.css" type="text/css" media="screen">
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:TextBox ID="txtName" runat="server" AccessKey="4"></asp:TextBox>
<asp:Button ID="btnSearch" runat="server" Text="Go" PostBackUrl="searchResults.aspx"/>
        <table style="width: 100%" height="100%" >
            <tr>
                <td colspan="2">
                <BIE:HEADER id="header1" Runat="server"></BIE:HEADER>
                </td>
            </tr>
            <tr>
                <td colspan="2">

                </td>
            </tr>

            <tr>
                <td colspan="2">
                </td>
            </tr>
        </table>

    </div>
    </form>
</body>
</html>
searchResults.aspx

Code:
<%@ Import Namespace="System.Data.OleDb" %>
<%@ Import Namespace="System.Configuration" %>
<%@ Import Namespace="System.Data" %>
<%@ Page Language="C#" EnableEventValidation="False" %>
<%@ PreviousPageType VirtualPath="~/default.aspx" %>



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
  
    public void Page_Load(object sender, EventArgs e)
    {

        if (PreviousPage != null && PreviousPage.IsCrossPagePostBack)
        {
           TextBox txtName = (TextBox)Page.PreviousPage.FindControl("txtName");
           GridView1.Visible = true;
        }


    }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
    <asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="<%$ connectionStrings: connString %>"

            SelectCommand="SELECT [Course_ID], [Course], [Mode] FROM [Courses] WHERE [Course] LIKE '%' + @Course + '%'">

            <SelectParameters>

                <asp:ControlParameter ControlID="txtName" Name="Course" PropertyName="Text" Type="String" />

            </SelectParameters>

        </asp:AccessDataSource>
            <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
                DataKeyNames="Course" DataSourceID="AccessDataSource1" CssClass="courselist64">
                <Columns>
                <asp:HyperLinkField DataTextField="Course" DataNavigateUrlFields="Course_ID" DataNavigateUrlFormatString="Results.aspx?CourseID={0}" HeaderStyle-CssClass="courselist64" >
                  </asp:HyperLinkField>                                
                    <asp:BoundField DataField="Mode" HeaderText="Mode" SortExpression="Mode"/>
                </Columns>
            </asp:GridView>
    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
    </form>
</body>
</html>
I would appreciate any ideas. Thanks







 
Old November 9th, 2006, 12:11 PM
Authorized User
 
Join Date: Mar 2005
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Never worry I found a solution to the problem. I dumped the PreviousPage dierctives after nothing would work. Instead I set up a querystring on the first page,

    public void btnSearch_Click(object sender, EventArgs e)
    {
        Response.Redirect("searchResults.aspx?Name=" + txtName.Text);
    }

Then on the second page assigned a label value to the querystring

  public void Page_Load(object sender, System.EventArgs e)
    {
        if (Request.QueryString["Name"] != null)
        {
            Label1.Text = Request.QueryString["Name"];
            GridView1.Visible = true;
        }

    }

I was then able to assign the Label1 id as the controlID for my ControlParameter.


<asp:ControlParameter ControlID="label1" Name="Course" PropertyName="Text" Type="String" />




 
Old March 8th, 2007, 05:31 PM
Registered User
 
Join Date: Mar 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Still has problem.

If I use label <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
then I get search result : any words match "label". for example: Labelle, Shirley ; Avery, Laquita Labelle ;....
Please Help.
Thanks.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Form post page redirect problem - S.O.S. jroxit ASP.NET 1.0 and 1.1 Professional 4 May 21st, 2008 11:06 AM
Cross Page Post Back problem akhilesh_g ASP.NET 2.0 Professional 2 December 24th, 2007 04:38 AM
Problem with Cross Page Post Back keaja ASP.NET 2.0 Basics 1 October 31st, 2006 07:00 AM
Cross Page Post Back shario ASP.NET 2.0 Basics 0 June 22nd, 2006 03:44 AM
post result on a different page Sheikha ADO.NET 2 September 12th, 2004 10:24 PM





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