如何使用是/否按钮获取警报消息? [英] how to get alert message with yes/no button?

查看:56
本文介绍了如何使用是/否按钮获取警报消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





如果在不使用onclientclick的情况下单击提交按钮,如何使用YES / NO按钮获取警告消息。

如果数据库表中没有值,那么我想显示YES / NO的警告消息。单击是时,需要启用文本框。我需要在不使用onclientclick的情况下执行此操作。

这是我使用过的一段代码,但它无效。

  protected   void  btnadd_Click( object  sender,EventArgs e)
{
< span class =code-keyword> 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.com/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:
http://www.aspsnippets.com/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);


这篇关于如何使用是/否按钮获取警报消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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