Javascript确认未弹出-ASP.net [英] Javascript confirm not popping up - ASP.net

查看:79
本文介绍了Javascript确认未弹出-ASP.net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个JavaScript可以确认是否为asp隐藏字段分配了一个值

Hi,

I have a javascript for confirm that assigns a value to an asp hidden field

function ConfirmBox(msg) {
    var x;
    if (confirm(msg))
    {
        document.getElementById('<% =inpHide.ClientID %>').value = "1";
        //return true;
    }
    else
    {
        document.getElementById('<% =inpHide.ClientID %>').value = "0";
        //return false;
    }

}



将使用以下代码从代码隐藏中调用该代码:



it will be called to from codebehind using this:

ClientScriptManager script = Page.ClientScript;

                            script.RegisterStartupScript(this.GetType(), "Error", "ConfirmBox('ADS Keymetrics General report already exists for this account for Q" + ADSImport.Upload.QTo + " " + ADSImport.Upload.YrTo + ". Do you want to overwrite the record?');", true);
                            
                            int DiagResult = int.Parse(inpHide.Value);
                            if (DiagResult == 1)
                            { ClientScript.RegisterClientScriptBlock(this.GetType(), "Error", "MessageBox('OK');", true); }




确认框不会弹出,当我跟踪代码时,它仅通过RegisterStartupScript代码并直接转到




the confirm box won''t pop-up and when i trace the code, it just passes by the RegisterStartupScript code and goes directly to

int DiagResult = int.Parse(inpHide.Value);

,这就是给我一个错误的原因:输入字符串的格式不正确."因为变量inpHide具有空值.

任何帮助都将不胜感激.

谢谢!

that''s why it gives me an error: "Input string was not in a correct format." since the variable inpHide has a null value.

any help is greatly appreciated.

Thanks!

推荐答案

好吧,您注入了JavaScript代码,然后立即尝试(在服务器端)访问所涉及控件之一的值.如何运作?

注入JavaScript不会设置该值.调用ConfirmBox()会设置该值,并发布,每当您尝试在服务器端访问该控件值时,您都将取回设置的值.

要么将逻辑移到适当的位置,要么将默认值设置为inpHide,以确保没有错误并且可以顺利进行.
Well, you inject a JavaScript code and then instantly try to access (on server side) value of one of the controls involved. How will it work?

Injecting JavaScript will not set the value. A call to ConfirmBox() will set the value and post that whenever you try to access that control value on server side, you will get back the set value.

Either, move your logic to a proper place or set a default value of inpHide such that there is no error and it can go on smooth.


这篇关于Javascript确认未弹出-ASP.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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