如何使此结果页面正常工作? [英] how to make this result page work?

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

问题描述

我有一个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; 
        }

    }

推荐答案

奇怪的情况.

Weird case.

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;}


Searchkey永远不会为null,因为它已经在顶部进行了初始化.请检查....
Searchkey will never be null, as its already initialized at the top. Pls check....


Anuja是正确的Searchkey可以为null,我想您应该更多的逻辑,先生.如果有错,现在请纠正我.您用于搜索的文本框将其放在母版页中,因为您要搜索页面中与文本框中的值匹配的值,并且文本框中的值将位于此处"Request.QueryString ["searchkey"] ;"

如果说的正确,为什么要在Page_Load上运行此代码?

如果(Searchkey!= null)
{
CreateResultTable();
}
其他
{
notifylabel.Text =请提供搜索关键词!";
}
Anuja is correct Searchkey can neva b a null, I think you should more logic sir...Now correct me if am wrong. The textbox you using to search, you put it in a masterpage because you want to search what ever value in the page matches with the value in the textbox and the value from the textbox will be inside here "Request.QueryString["searchkey"];"

if what am saying is correct,why are you running this code on Page_Load?

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


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

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