查询字符串不起作用 [英] Query String is not working

查看:95
本文介绍了查询字符串不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个Search.aspx和SearchResult.aspx文件。当我搜索Search.aspx中存在的TextBox中的任何东西时,它会在Search.aspx文件中返回结果。在我的结果中,我得到一些LinkBut​​ton,我想点击进入SearchResult.aspx文件,详细搜索结果。但是,我认为在这种情况下我的代码不起作用。

我的代码:

Hi,
I have a Search.aspx and SearchResult.aspx files. When Iam searching any thing in a TextBox which is exist in Search.aspx fle it return in Search.aspx file with result. In my result I get some LinkButton where I want to click to go in SearchResult.aspx file with elaborate of search result. But, I think in this case my code is not working.
My Code:

private void lnkSearch_Command(object sender, CommandEventArgs e)
        {
            string commandName = e.CommandName;
            if (commandName.Length > 0)
            { 
                Response.Redirect("SearchResult.aspx?SearchResult=" + commandName.ToString() + "&SearchKey=" + txtSearch.Text.ToString());
            }
            else
                Response.Redirect("SearchResult.aspx?SearchKey=Error for loading page...");
        }



当我加载Search.aspx页面时:


When I am loading Search.aspx page:

if (!IsPostBack == true)
            {
for (int i = 0; i < db.dataSet.Tables["searchResult"].Rows.Count; i++)
                {
                    LinkButton lnkSearch = new LinkButton();
                    lnkSearch.Text = txtSearch.Text.ToString();
                    lnkSearch.ID = "lnkBtn" + i.ToString();
                    lnkSearch.EnableViewState = true;
                    //lnkSearch.AccessKey = db.dataSet.Tables["searchResult"].Rows[i][0].ToString();
                    lnkSearch.Command += new CommandEventHandler(lnkSearch_Command);
                    lnkSearch.CommandName = db.dataSet.Tables["searchResult"].Rows[i][0].ToString();
                    this.UpdatePanel1.ContentTemplateContainer.Controls.Add(lnkSearch);
                    this.UpdatePanel1.ContentTemplateContainer.Controls.Add(new LiteralControl("<br/>"));
}



此工作正常。但是,如果发生LinkBut​​ton_Command,这是行不通的。因为,当我在LinkBut​​ton中叮当作响时,它只是使用以前的查询字符串网址刷新此页面,但不会使用SearchResult.aspx文件。



所以,请帮我。我怎么解决呢。


This working good. But, in the event of LinkButton_Command, this is not working. Cause, when I am clinking in the LinkButton it just refreshing this page with previous Query String url but not going on SearchResult.aspx file.

So, please help me. How can I solve it.

推荐答案

需要在Page的Init事件中创建动态控件,而不是Load事件。



不检查IsPostback,因为每次创建页面时都需要重新创建控件,因此在Init事件之后加载ViewState和Event信息时,但在Load事件之前加载它时,它就存在。



请参阅 http://www.4guysfromrolla.com/articles/ 092904-1.aspx [ ^ ]获取更多信息。
Dynamic controls need to be created in the Init event of the Page, not the Load event.

Do not check for IsPostback as the control needs to be recreated each time the page is created so it exists when ViewState and Event information is loaded AFTER the Init event, but BEFORE the Load event.

see http://www.4guysfromrolla.com/articles/092904-1.aspx[^] for some more information.


这篇关于查询字符串不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆