ASP.NET 2.0 Post to another Page Search Problem (txtName)

Last post 03-08-2007 3:43 PM by zhuhhu. 4 replies.

Sort Posts:

  • ASP.NET 2.0 Post to another Page Search Problem (txtName)

    11-09-2006, 7:53 AM
    • Member
      35 point Member
    • Indo77
    • Member since 11-09-2006, 11:57 AM
    • Posts 11

    Hi Everyone, I am upgrading from 1.1 to 2.0 and have experienced a lot of teasing problems.  I wonder if anyone can help me with the latest one.  I have set up a page called "Default.aspx" that contains a search text box called txtName and a button. This is my first page.  I want to post the results of the text search on a another page called searchResults (my Page 2).  The results are based on a search by potential students for courses at our Institute.  However when I try to access the page I get an error thrown up like this.

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

    Bear in mind I need "txtName" as the ControlD for my ControlParameter on the second page.



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

    <%@ PreviousPageType VirtualPath="~/Default.aspx" %>


    and used it with

        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

     
    1    "BIE" TagName="header" Src="header.ascx" %>
    2    "C#" %>
    3    
    4    "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    5    
    6    <script runat="server"&gt;
    7    </script>
    8    
    9    <html xmlns="http://www.w3.org/1999/xhtml" >
    10   "server">
    11       
    12       "stylesheet" href="stylecss.css" type="text/css" media="screen">
    13   
    14   
    15       "form1" runat="server">
    16       
    17 "txtName" runat="server" AccessKey="4"> 18 "btnSearch" runat="server" Text="Go" PostBackUrl="~/searchResults.aspx"/> 19 "width: 100%" height="100%" > 20 21 24 25 26 29 30 31 32 34 35
    "2"> 22 "header1" Runat="server"> 23
    "2"> 27 28
    "2"> 33
    36 37
    38 39 40
     
    searchResults.aspx
     
    1    "System.Data.OleDb" %>
    2    "System.Configuration" %>
    3    "System.Data" %>
    4    "C#" EnableEventValidation="False" %>
    5    "~/default.aspx" %>
    6    
    7    
    8    
    9    "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    10   
    11   <script runat="server"&gt;
    12     
    13       public void Page_Load(object sender, EventArgs e)
    14       {
    15   
    16           if (PreviousPage != null && PreviousPage.IsCrossPagePostBack)
    17           {
    18              TextBox txtName = (TextBox)Page.PreviousPage.FindControl("txtName");
    19              GridView1.Visible = true;
    20           }
    21           
    22   
    23       }
    24   
    25   </script>
    26   
    27   <html xmlns="http://www.w3.org/1999/xhtml" >
    28   "server">
    29       
    30   
    31   
    32   "form1" runat="server">
    33       "AccessDataSource1" runat="server" DataFile="&lt;%$ connectionStrings: connString %>"
    34   
    35               SelectCommand="SELECT [Course_ID], [Course], [Mode] FROM [Courses] WHERE [Course] LIKE '%' + @Course + '%'">
    36   
    37               
    38   
    39                   "txtName" Name="Course" PropertyName="Text" Type="String">
    40   
    41               
    42   
    43           
    44               "GridView1" runat="server" AutoGenerateColumns="False"
    45                   DataKeyNames="Course" DataSourceID="AccessDataSource1" CssClass="courselist64">
    46                   
    47                   "Course" DataNavigateUrlFields="Course_ID" DataNavigateUrlFormatString="Results.aspx?CourseID={0}" HeaderStyle-CssClass="courselist64" >
    48                     								
    49                       "Mode" HeaderText="Mode" SortExpression="Mode"/>
    50                   
    51               
    52       "Label1" runat="server" Text="Label">
    53       
    54   
    55   
    
      

    If anyone has any ideas I would appreciate the feedback.  I am lost and have tried following various Post to another Page tutorials.

  • Re: ASP.NET 2.0 Post to another Page Search Problem (txtName)

    11-10-2006, 8:15 AM
    • Member
      35 point Member
    • Indo77
    • Member since 11-09-2006, 11:57 AM
    • Posts 11
    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" />
  • Re: ASP.NET 2.0 Post to another Page Search Problem (txtName)

    02-27-2007, 6:26 PM
    • Member
      14 point Member
    • ReTox
    • Member since 01-14-2004, 7:04 AM
    • Posts 4
    Same over here. Lost 2 hours trying to make it actually work and it doesn't No
    PreviousPage is always null and IsCrossPagePostBack is always false

    I'll guess I'll have to make a workaround with Transfer()

  • Re: ASP.NET 2.0 Post to another Page Search Problem (txtName)

    03-08-2007, 3:35 PM
    • Member
      14 point Member
    • zhuhhu
    • Member since 03-08-2007, 3:31 PM
    • Posts 7

    Still has problem:
    see below:
    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

    if <..Text="Lable">
    Then search result from is to match any words including "Label"
    if <..Text="Name">
    Then search result is to match any words including "Name"

    How?

    Please Help ASAP.
    Thanks.

  • Re: ASP.NET 2.0 Post to another Page Search Problem (txtName)

    03-08-2007, 3:43 PM
    • Member
      14 point Member
    • zhuhhu
    • Member since 03-08-2007, 3:31 PM
    • Posts 7

    Still has problem:
    see below:
    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

    if <..Text="Lable">
    Then search result  is to match any words including "Label"
    if <..Text="Name">
    Then search result is to match any words including "Name"

    Please Help ASAP.
    Thanks.

Page 1 of 1 (5 items)