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">
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 | "2"> 22 "header1" Runat="server"> 23 | 24
25 26 | "2"> 27 28 | 29
30
31 32 | "2"> 33 | 34
35
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">
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="<%$ 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.