如何使用是/否按钮获取警报消息?

编程入门 行业动态 更新时间:2024-10-26 18:28:03
本文介绍了如何使用是/否按钮获取警报消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如果在不使用onclientclick的情况下单击提交按钮,如何使用YES / NO按钮获取警告消息。 如果数据库表中没有值,那么我想显示YES / NO的警告消息。单击是时,需要启用文本框。我需要在不使用onclientclick的情况下执行此操作。 这是我使用过的一段代码,但它无效。

protected void btnadd_Click( object sender,EventArgs e) { string product_descr; product_descr = getdata(); // ScriptManager.RegisterStartupScript(this,GetType(),displayalertmessage,Confirm(); ,true); if (product_descr == null || product_descr = = ) { string confirmValue = Request.Form [ confirm_value]; if (confirmValue == 是 ) { txtProductName.Enabled = false ; txtVersion.Enabled = false ; txtDescription.Visible = true ; lblDescription.Visible = true ; } else { txtProductName.Text = ; txtVersion.Text = ; } } else { lblDescription.Visible = 真; txtDescription.Visible = true ; txtDescription.Text = product_descr; } }

Getdata()函数是从数据库表中获取值。 javascript

< script type = text / javascript> function 确认(){ var confirm_value = document .createElement( INPUT); confirm_value.type = hidden; confirm_value.name = confirm_value; if (确认( 输入值为产品名称和版本不存在。按好以创建新的。)){ confirm_value.value = 是; } else { confirm_value.value = 否; } document .forms [ 0 ]。appendChild(confirm_value); } < / script>

执行此代码时,在btnadd_Click事件后抛出警告消息YES / No的代码不起作用。

解决方案

首先,使用

if (!string.IsNullOrEmpty(product_descr))

而不是

if(product_descr == null || product_descr ==)

。 无论你有什么按钮,将您的javascript函数放在OnClientClick中。你可以得到价值。如果您想在Javascript中使用getData()函数,请将其设置为Web方法并在javascript中使用。 选中: HTTP: //www.aspsnippets/Articles/Confirmation-Confirm-box-with-Yes-No-Buttons-Options-using-AJAX-Modal-Popup-Extender-in-ASPNet.aspx [ ^ ] 问候, Praneet

OnClientClick是这里使用的最佳选择。 < asp:button id =btnClicktext =点击此处runat =serveronclick =btnClick_Clickonclientclick =确认()xmlns:asp =#unknown/> 为什么你不想使用OnClientClick()? 以下代码不适用于您的情况。执行方法btnadd_Click()后,脚本代码将起作用。这就是为什么confirmValue只返回null。 ScriptManager.RegisterStartupScript(this,GetType(),displayalertmessage,Confirm();,true);

Hi, How to get a alert message with YES/NO button, when a submit button is clicked without using onclientclick. If there is no value from database table, then i wanted to show alert message with YES/NO. When YES is clicked then a textbox need to be enabled. I need to do this without using onclientclick. Here is the piece of code i used but it is not working.

protected void btnadd_Click(object sender, EventArgs e) { string product_descr; product_descr = getdata(); //ScriptManager.RegisterStartupScript(this, GetType(), "displayalertmessage", "Confirm();", true); if (product_descr == null || product_descr == "") { string confirmValue = Request.Form["confirm_value"]; if (confirmValue == "Yes") { txtProductName.Enabled = false; txtVersion.Enabled = false; txtDescription.Visible = true; lblDescription.Visible = true; } else { txtProductName.Text = ""; txtVersion.Text = ""; } } else { lblDescription.Visible = true; txtDescription.Visible = true; txtDescription.Text = product_descr; } }

Getdata() function is to get the value from database table. javascript

<script type = "text/javascript"> function Confirm() { var confirm_value = document.createElement("INPUT"); confirm_value.type = "hidden"; confirm_value.name = "confirm_value"; if (confirm("Entered value for Product Name and Version doesn't exist.Press Okay to create a New.")) { confirm_value.value = "Yes"; } else { confirm_value.value = "No"; } document.forms[0].appendChild(confirm_value); } </script>

When executing this code the alert message is thrown after btnadd_Click event and code for YES/No is not working.

解决方案

Hi, Firstly, use

if(!string.IsNullOrEmpty(product_descr))

instead of

if (product_descr == null || product_descr == "")

. And wherever you have your button, put your javascript function in your OnClientClick. The you can get the value. If you want your getData() fucniton in Javascript, make it a web Method and use in javascript. Check this: www.aspsnippets/Articles/Confirmation-Confirm-box-with-Yes-No-Buttons-Options-using-AJAX-Modal-Popup-Extender-in-ASPNet.aspx[^] Regards, Praneet

Hi, OnClientClick is the best option here to use. <asp:button id="btnClick" text="Click here" runat="server" onclick="btnClick_Click" onclientclick="Confirm()" xmlns:asp="#unknown" /> Why you don't want to use OnClientClick()? Below code will not work in your case. The script code will work after executing the method btnadd_Click(). That's why confirmValue returns null only. ScriptManager.RegisterStartupScript(this, GetType(), "displayalertmessage", "Confirm();", true);

更多推荐

如何使用是/否按钮获取警报消息?

本文发布于:2023-11-27 16:54:03,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1638828.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:警报   如何使用   按钮   消息

发布评论

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

>www.elefans.com

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