本文介绍了如何使此结果页面正常工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我有一个Web应用程序,并且在其中使用了搜索选项.我的搜索输入框在maser页面中,我通过使用Request.QueryString ["searchkey"]将该值带到搜索页面中;之后,我要在搜索页面上单击一个按钮.但是,当我单击该结果消失.和请提供要搜索的关键字!"被展示.我尝试了Page.Ispostback == false和!ispostback.它没有用.有人可以分析我的代码并给我解决方案吗?这是我的代码,
我只是想将搜索关键字保留在一个不会发生任何变化的地方..

i have a web application and i uaed a search option in it. my search input box is in the maser page and i take that value to the search page by using Request.QueryString["searchkey"]; after that i wanna click a button on the search page. but when i click that the result goes away. and "Please provide a keyword for searching!" is displayed. i tried Page.Ispostback == false and !ispostback. it didn''t work. can somebody analyze my code and give me a solution?? here''s my code,
i just wanna keep the search key in a place that whatever happens it doesnt change..

public partial class SearchMovie : System.Web.UI.Page
{
    String Searchkey = "acc";

    protected void Page_Load(object sender, EventArgs e)
    {
        setSearchKey();

        if (Searchkey != null)
        {
                CreateResultTable();
        }
        else
        {
            notifylabel.Text = "Please provide a keyword for searching!";
        }
    }

    private void setSearchKey()
    {
        String Srchkey = Request.QueryString["searchkey"];

            if (Srchkey != null || Srchkey != "")
            {
                Searchkey = Srchkey;
                Session["search"] = Searchkey;
            }

    }

    public void CreateResultTable()
    {
        MoviesGenDataContext search = new MoviesGenDataContext();

        var srchreslt = from srch in search.Item_Masters
                    where SqlMethods.Like(srch.Name, "%"+ Searchkey +"%")
                    select srch;

        foreach (var rslt in srchreslt)
        {
                TableRow row = new TableRow();
                TableCell cell1 = new TableCell();
                TableCell cell2 = new TableCell();
                TableCell cell3 = new TableCell();


                Label desc = new Label();
                LiteralControl h1start = new LiteralControl("<h1>");
                LiteralControl h1end = new LiteralControl("</h1>");
                desc.Text = rslt.Item_Desc;

                HyperLink movlk = new HyperLink();
                HyperLink play = new HyperLink();
                HyperLink book = new HyperLink();

                if (Session["email"] == null)
                {
                    book.Enabled = false;
                    notifylabel.Text = "Please log in to book the DVD(s)!";
                }
                else
                {
                    book.Enabled = true;
                }

                LiteralControl nln = new LiteralControl("<br/>");
                LiteralControl nln2 = new LiteralControl("&nbsp;");

                play.ImageUrl = "Images/playtrailer.gif";
                play.NavigateUrl = "SearchMovie.aspx?Vn=Trailers/" + rslt.Name.Trim() + ".flv";


                book.ImageUrl = "Images/bookDVD.gif";
                book.NavigateUrl = "MyReservations.aspx?Vn=" + rslt.Name.Trim() + "&Vy=" + rslt.Year + "&Vs=" + rslt.Starring.Trim();

                movlk.ImageUrl = "Posters/" + rslt.Name.Trim() + ".jpg";
                movlk.NavigateUrl = "SearchMovie.aspx?Vn=Trailers/" + rslt.Name.Trim() + ".flv";

                cell1.Controls.Add(movlk);
                cell1.Width = Unit.Pixel(214);
                cell2.Width = Unit.Pixel(200);
                cell2.Controls.Add(h1start);
                cell2.Controls.Add(desc);
                cell2.Controls.Add(h1end);
                cell2.Controls.Add(nln);

                cell3.Controls.Add(play);
                cell3.Controls.Add(nln);
                cell3.Controls.Add(book);

                row.Cells.Add(cell1);
                row.Cells.Add(cell2);
                row.Cells.Add(cell3);
                Srchresult.Rows.Add(row);

            }
        //Session["resultable"] = Srchresult;
        }

    }

推荐答案

setSearchKey();
if (Searchkey != null)
{
        CreateResultTable();
}
else
{
    notifylabel.Text = "Please provide a keyword for searching!";
}



在Page_Load方法中,您正在基于Searchkey对象通过CreateResultTable方法处理搜索.

您以acc开头初始化了Searchkey.万一setSearchKey失败,您将继续拥有acc权限;否则为QueryString中的非null值.

无论哪种情况,您在Searchkey中都应具有非null值.不幸的是,程序执行无法满足以下条件



In Page_Load method, you are processing the search through CreateResultTable method on the basis of Searchkey object.

You initialized Searchkey in the beginning with acc. In case, setSearchKey fails, you will continue to have acc; otherwise non null values from QueryString.

Either case, you should have non null values in Searchkey. Unfortunately, program execution fails the below condition

if (Searchkey != null)



并移至notifyLabel.

一种解决方案是使用自动获取器和设置器将Searchkey移入公共财产,如:



and moving to notifyLabel.

One solution would be moving Searchkey into public property with auto getter and setter as:

public String Searchkey {get;set;}




这篇关于如何使此结果页面正常工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-08 09:21