【发布时间】:2011-11-22 22:29:11
【问题描述】:
问题 1
我正在尝试在子页面中使用位于母版页上的搜索按钮的 Onclick 事件。我在这个网站上找到了一个很好的解决方案,但它不起作用。
链接: How to handle master page button event in content page?
与该解决方案的不同之处在于我的 IpageInterface 位于 App_Code 文件夹中,并且位于命名空间 Business 中。
除此之外,它几乎是一样的。
所以我有 IpageInterface 类:
namespace Business {
public interface IpageInterface {
void DoSomeAction();
}
}
然后在我的母版页上:
using Business;
public partial class site : System.Web.UI.MasterPage {
protected void SearchQuery_Click(object sender, EventArgs e) {
IpageInterface pageInterface = Page as IpageInterface;
if (pageInterface != null) {
pageInterface.DoSomeAction();
}
}
}
最后我有了,在我想使用的页面上(结果页面,因为按钮是搜索按钮):
using Business;
public partial class results : System.Web.UI.Page, IpageInterface {
public void DoSomeAction() {
ContentPlaceHolder mainContent = (ContentPlaceHolder)Master.FindControl("mainContent");
if (mainContent != null) {
DropDownList ddlSearchOn = (DropDownList)mainContent.FindControl("ddlSearchOn");
TextBox TxtSearch = (TextBox)mainContent.FindControl("TxtSearch");
if (ddlSearchOn.Text == "Everything" || ddlSearchOn.Text == "Title" || ddlSearchOn.Text == "Text") {
List<News> newsSearchResults = News.SearchNews(ddlSearchOn.Text, TxtSearch.Text);
foreach(News newsArticle in newsSearchResults) {
newsArticle.Text = LimitCharacters(newsArticle.Text, 350);
}
repeaterSearchResults.DataSource = newsSearchResults;
repeaterSearchResults.DataBind();
}
}
}
但是当我按下按钮时,我查看了 pageInterface 的值,它说它是空的。
问题 2
编辑: 问题2解决了。我在外键关系窗口中的删除规则旁边选择了“级联”。
除了这个问题,我还有第二个 MS SQL 问题,如下所示: 我有带有 cmets 的新闻文章,当我想删除文章时,我也必须删除 cmets,所以我使用以下查询:
SqlCommand cmd = new SqlCommand(@"DELETE FROM News_comments WHERE News_comments.news_Id = @news_Id AND News_comments.account_Id = @account_Id;
DELETE FROM News_news WHERE News_news.news_Id = @news_Id"
, conn);
问题是,尽管 cmets 已被删除,但文章似乎仍然有 cmets。所以我不能删除这篇文章。 例外是:
"The DELETE statement conflicted with the REFERENCE constraint" exception.
将不胜感激所需的帮助!
【问题讨论】:
-
如果您在 cmets 表中设置了外键以在源表中的关联行(文章) 被删除。
-
没关系,我只是通过url将所需的信息提供给子页面。
标签: sql asp.net sql-server controls sql-delete