我有一個Search.aspx
頁面文本框和按鈕。 postback
是Results.aspx
它有一個GridView。 Sql查詢的工作原理與QueryDesigner一樣。Click Event Event For Cross Page PostBack
理論上,僞搜索應該通過在文本框中輸入一個值並點擊按鈕來完成。當我輸入一個值並單擊時,Results.aspx
頁面打開,但爲空。
在Search.aspx
click事件無非是:
protected void Button2_Click(object sender, EventArgs e){}
此設置的確在Web項目的工作,但是,將無法在Web站點,這這是。看起來,點擊事件不起作用,因爲沒有將該值提交到Results.aspx
頁面。我沒有找到可以正常工作的點擊事件。我將不勝感激任何幫助。
編輯:SQL查詢很複雜,但正如我所說的,它在查詢設計器中輸入值時工作正常。我確實爲.cs添加了「命名空間」作爲網站,而不是Web項目,通常沒有命名空間。
Search.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Search.aspx.cs" Inherits="LinqTest.Search" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox runat="server" ID="Name"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Search" PostBackUrl="~/Results.aspx" />
</div>
</form>
</body>
</html>
Search.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace LinqTest
{
public partial class Search : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
}
}
}
ResultsSearch.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ResultsSearch.aspx.cs" Inherits="RecipeFaire.ResultsSearch" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<%@ PreviousPageType VirtualPath="~/Search.aspx" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<!-- this is the results of the search done on the search.aspx -->
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:ListView ID="ListView1" runat="server" DataKeyNames="RecipeID" DataSourceID="SqlDataSource1">
<ItemTemplate>
<tr>
<td rowspan="2">
<asp:Image ID="Image1" runat="server" Width="100px" Height="80px" ImageUrl='<%# "~/Handler.ashx?RecipeID=" + Eval("RecipeID")%>' />
</td>
<td rowspan="2" width="100px">
<asp:Rating ID="Rating1" runat="server" align="right" valign="top" CurrentRating='<%# Eval("RatingAVG")%>'
MaxRating="5" ReadOnly="true" StarCssClass="ratingStar" WaitingStarCssClass="savedRatingStar"
FilledStarCssClass="filledRatingStar" EmptyStarCssClass="emptyRatingStar">
</asp:Rating>
   <br></br>
<asp:Label ID="Label7" runat="server" align="right" Text='<%# Eval("Count") %>' />  
<asp:HyperLink ID="Home" Font-Size="Small" runat="server" NavigateUrl='<%# Bind("RecipeID", "../../Comments.aspx?RecipeId={0}") %>'
Text="Reviews" />
</td>
<td>
<asp:HyperLink ID="HyperLink2" runat="server" NavigateUrl='<%# Bind("RecipeID", "PageLinkDetails.aspx?RecipeId={0}") %>'
Text='<%# Eval("RecipeName") %>'></asp:HyperLink>
</td>
</tr>
<tr style="width: 500px">
<td>
<asp:Label ID="DescriptionLabel" valign="top" runat="server" Text='<%# Eval("Description") %>' />
</td>
</tr>
<tr>
<td colspan="5" style="color: LightGrey">
<asp:Label ID="Label2" runat="server" Font-Size="1px" Height="1px" Text='<%# Eval("RecipeID") %>'></asp:Label>
<hr style="border-style: dotted" />
</td>
</tr>
</ItemTemplate>
<LayoutTemplate>
                         <asp:LinkButton
runat="server" ID="SortByName" CommandName="Sort" CommandArgument="RecipeName">Sort By Recipe Name</asp:LinkButton>
              
<asp:LinkButton runat="server" ID="SortByPrice" CommandName="Sort" CommandArgument="RatingAVG">Sort By Rating</asp:LinkButton>
<table id="Table1" runat="server">
<tr id="Tr1" runat="server">
<td id="Td1" runat="server">
<table id="itemPlaceholderContainer" runat="server" border="0" style="">
<tr id="Tr2" runat="server" style="">
<th id="Th1" runat="server">
</th>
</tr>
<tr id="itemPlaceholder" runat="server">
</tr>
</table>
</td>
</tr>
<tr id="Tr3" runat="server">
<td id="Td2" runat="server" style="" align="center">
<asp:DataPager ID="DataPager2" PagedControlID="ListView1" PageSize="8" runat="server">
<Fields>
<asp:NumericPagerField ButtonCount="8" />
</Fields>
</asp:DataPager>
</td>
</tr>
</table>
</LayoutTemplate>
</asp:ListView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:RecipeUploadConnectionString %>"
SelectCommand="SELECT pr.RecipeID, pr.CategoryName, pr.CategoryType, pr.RecipeName, pr.Description, COUNT(rr.RecipeID) AS Count, AVG(rr.Rating) AS RatingAVG
FROM PostedRecipes AS pr LEFT OUTER JOIN RecipeRatings AS rr ON pr.RecipeID = rr.RecipeID
WHERE pr.RecipeName LIKE '%' + @RecipeName + '%' OR pr.CategoryName LIKE '%' + @CategoryName + '%'
OR pr.CategoryType LIKE '%' + @CategoryType + '%' OR pr.CuisineOrigin LIKE '%' + @CuisineOrigin + '%'
OR pr.CuisineType LIKE '%' + @CuisineType + '%' GROUP BY pr.RecipeID, pr.RecipeName, pr.CategoryName, pr.CategoryType, pr.CuisineOrigin, pr.CuisineType, pr.Description">
<SelectParameters>
<asp:FormParameter FormField="RecipeName" Name="RecipeName" Type="String"/>
<asp:FormParameter FormField="CategoryName" Name="CategoryName" Type="String" />
<asp:FormParameter FormField="CategoryType" Name="CategoryType" Type="String"/>
<asp:FormParameter FormField="CuisineOrigin" Name="CuisineOrigin" Type="String" />
<asp:FormParameter FormField="CuisineType" Name="CuisineType" Type="String"/>
</SelectParameters>
</asp:SqlDataSource>
</div>
</form>
</body>
</html>
ResultsSearch.cs
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Text;
using System.Web.SessionState;
namespace RecipeFaire
{
public partial class ResultsSearch : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
}
可以顯示一些代碼?任何錯誤等? – christiandev
感謝您的努力。代碼在上面。我沒有收到任何錯誤消息,只是目標頁面上的空白頁面。具有或不具有「命名空間」的結果相同。 – user1830924
請顯示您的Search.aspx的完整標記。必須有一些更多的標記,否則它將不能像驗證一樣工作,或者你確定在Search.aspx中只使用了這麼多的標記? –