ASP.NET搜索网页 [英] ASP.NET Searching webpage

查看:75
本文介绍了ASP.NET搜索网页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我想知道,如果我要在asp.net中搜索特定专辑,它将显示该专辑,但是如果说我在搜索特定专辑中键入的文本框为空白,该如何编码说您输入的结果为空白?

我所有在其上带有搜索文本框的页面,当您键入时都会将您重定向到带有标签以显示错误或如果找到了搜索结果的搜索结果页面,那么它将在数据列表上显示专辑.

谢谢.

Hi
Id like to know, if I was to search for a particular album in my asp.net , it will show the album, but if say the text-box where I type in the search for a particular album is blank, how do I code it to say that result you have typed is blank?

All my pages that have the search text box on them , when you type it redirects you to a search result page that has a label to display the error or if it finds the search, then it shows the album on a data list.

Thanks.

推荐答案

我假设您要通过单击搜索来验证文本框是否为空白.
您可以使用客户端Javascript来警告用户,也可以使用服务器端消息来通知文本框为空.

Javascript方法:

I am assuming that you want to validate your textbox that whether it is blank or not on click of Search.
You can either use client side Javascript to alert the user or use a server side message to inform that textbox is blank.

Javascript Method:

function validateText()
{
    if(document.getElementById("txtSearch").value == '')
    {
        alert("Please enter album name to search");
        return false;
    }
    else
        return true;
}



在搜索按钮的ClientClick上调用上述Javascript函数,如下所示:



Call the above Javascript funtion on the ClientClick of your Search button as below:

<asp:button id="btnSearch" name="Search" onclientclick="return validateText()" onclick="btnSearch_Click"></asp:button>



ServerSide方法:

在btnSearch_Click事件中,编写代码以显示所需的消息.



ServerSide Method:

Inside btnSearch_Click event, write a code to display required message.

void btnSearch_Click(object sender, EventArgs e) 
{
    if(txtSearch.Text == "" || txtSearch.Text == string.Empty)
    { 
       lblMessage.Text = "Please enter album name to search.";
    }
}



希望对您有所帮助.



Hope this helps.


使用RequiredFieldValidator控件在客户端和服务器端进行验证.
Use RequiredFieldValidator control for validation on client side & server side.


这篇关于ASP.NET搜索网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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