Problem 1
I’m trying to use an Onclick event from a search button, that is located on the master page, in a child page. I found a good solution on this site but it doesn’t work.
Link to it:
How to handle master page button event in content page?
The difference with that solution is that my IpageInterface is located in the App_Code folder and is in the namespace Business.
Other then that it’s pretty much the same.
So I have the IpageInterface class:
namespace Business {
public interface IpageInterface {
void DoSomeAction();
}
}
Then on my master page I have:
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();
}
}
}
And finally I have, on the page I want to use it (results page, because the button is a search button):
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();
}
}
}
But when I press the button, and I look at the value of pageInterface it says it’s null.
Problem 2
EDIT:
Problem 2 is solved. I selected ‘Cascade’ next to the delete rule in Foreign Key relationships window.
Besides that problem I have a second problem with MS SQL which goes as follows:
I have news articles with comments, when I want to remove the article I have to remove the comments as well, so I use the following query:
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);
The problem is though, that it still seems to thing that the article still has comments, eventhough the comments are removed. So I can’t remove the article.
The exception is:
"The DELETE statement conflicted with the REFERENCE constraint" exception.
Would appreciate the needed help!
It’s not really a solution to the problem I had with the code above but it is a solution to my situation.
I just give the needed info to the child page through the url. It’s not personal or restricted data so it’s not a problem.