在ASP .Net中创建警报或确认框 [英] Creating alert or confirmation box in ASP .Net

查看:91
本文介绍了在ASP .Net中创建警报或确认框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在ASP.Net中创建警报或确认框.
如果出现某些错误(例如文本框为空),则显示警报框.

有任何建议,请帮忙.

How to Create alert or confirmation box in ASP.Net.
alert box if some error occurs like if text box is empty or so.

any suggestions, please help.

推荐答案

有关CP的好文章,以创建一个简单的ASP.NET服务器控件,用作消息框和确认框
一个简单的ASP.NET服务器控件:消息框&确认框 [ ^ ]

关于CP本身的另一篇文章:
按钮,消息框和确认框在ASP.NET 3.5中 [
A good article on CP, to create a simple ASP.NET server control that functions as Message Box and Confirmation Box
A Simple ASP.NET Server Control: Message Box & Confirmation Box[^]

Another article on CP itself:
Buttons, Message Box, and Confirm Box in ASP.NET 3.5[^]




非常简单,假设您有一个文本框和一个按钮,并且想要在按钮的文本为空时提醒用户单击该按钮,

Hi,

Its very easy, assumed that you have a textbox and a button and you want to alert the user on the button click if its text is empty,

<table>
       <tr>
           <td>
               <asp:textbox id="txtTest" runat="server" xmlns:asp="#unknown"></asp:textbox>
           </td>
           <td>
               <asp:button id="btnTest" runat="server" text="Click Me!!!" onclientclick="return ShowAlert();" xmlns:asp="#unknown" />
           </td>
       </tr>
   </table>



现在,这里是当文本框为空时获取警报的javascript函数.



now here is the javascript function to get the alert when the textbox is empty.

<script type="text/javascript">
       function ShowAlert() {
           var txt = document.getElementById('txtTest').Value;
           if (txt == '') {
               alert('textbox is empty');
               //or if you want to get a confirm alert Box then
               if (confirm('Do you want ot proceed?')) {
                   alert('proceeding................');
               }
               else {
                   alert('canceled.................');
               }
           }
       }
   </script>


这篇关于在ASP .Net中创建警报或确认框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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