ASP.NET搜索网页

编程入门 行业动态 更新时间:2024-10-25 00:25:08
本文介绍了ASP.NET搜索网页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

嗨 我想知道,如果我要在asp中搜索特定专辑,它将显示该专辑,但是如果说我在搜索特定专辑中键入的文本框为空白,该如何编码说您输入的结果为空白? 我所有在其上带有搜索文本框的页面,当您键入时都会将您重定向到带有标签以显示错误或如果找到了搜索结果的搜索结果页面,那么它将在数据列表上显示专辑. 谢谢.

Hi Id like to know, if I was to search for a particular album in my asp , 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搜索网页

本文发布于:2023-11-28 19:32:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1643682.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:网页   ASP   NET

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!