如何避免使用脚本在asp.net中的formview中单击多个按钮 [英] how to avoid multiple button click in formview in asp.net using script

查看:56
本文介绍了如何避免使用脚本在asp.net中的formview中单击多个按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

这里我需要如何避免多次点击,这里我完成了那个过程。现在需要的是如果我点击保存验证消息显示两个时间以避免这种情况。 />


编码是: -



脚本:



 function ClientSideClick(myButton){

if typeof (Page_ClientValidate)== ' function'
{
if (Page_ClientValidate()== false
{返回 false ; }
}


if (myButton.getAttribute(' type')== ' button'){

myButton.disabled = true ;

}





按钮是: -



< asp:按钮ID =   InsertButton runat =   server CausesValidation =   True CommandName =  插入 
CssClass = savebutton1231 EnableTheming = false SkinID = skinBtnSave onclientclick = ClientSideClick(this) UseSubmitBehavior = f另外 OnClick = InsertButton_Click>< / asp:Button>









i需要如何避免两次相同的验证消息。

解决方案

如果使用更新面板,一旦客户端使用css单击按钮,您可以使屏幕变灰。这样可以防止二次点击。



 <   ProgressTemplate  >  
< div class = divWaiting >





。divWaiting {
position:absolute;
background-color:black;
z-index:2147483647!important;
不透明度:0.6;
溢出:隐藏;
text-align:center;顶部:0;左:0;
身高:100%;
宽度:100%;
填充顶部:20%;
}


我成功地使用了以下解决方案。我从我的同事那里得到了这个剧本。它使用JavaScript函数来禁用和启用按钮。禁用它时也会将按钮图像设置为.gif以指示处理。



如果已经将其作为另一个线程的解决方案发布,请原谅我。



  function  disableBtn(btnID,newText){
// 初始化以避免'Page_IsValid未定义'JavaScript错误
Page_IsValid = ;
// 检查页面是否请求任何验证
// 如果是,请检查页面是否有效
if typeof (Page_ClientValidate)== ' function '){
Page_ClientValidate();
// 您也可以传递验证组名称
}
// 变量
var btn = document .getElementById(btnID);
var isValidationOk = Page_IsValid;
/ * ******* NEW UPDATE *********** ************************* /
// 如果不是IE,则在重定向/渲染之前启用卸载按钮
if navigator .appName!== ' Microsoft Internet Explorer'
{
EnableOnUnload(btnID,btn.value);
}
/ * ********** END UPDATE *** ************************* /
// isValidationOk不为空
如果(isValidationOk!== null ){
// 页面有效
if (isValidationOk){
btn.disabled = true ;
btn.value = newText;
btn.style.background = ' url(〜/ images / ajax-loader.gif)';
}
其他 { // 页面无效
btn.disabled = false ;
}
}
其他 { // 页面没有任何验证请求
setTimeout( setImage(' + btnID + ') 10 );
btn.disabled = true ;
btn.value = newText;
}
}

// 设置背景图片按钮
function setImage(btnID)
{
var btn = document .getElementById(btnID);
btn.style.background = ' url(images / loading.gif)';
}

// 启用按钮并恢复原始文本值
function EnableOnUnload(btnID,btnText)
{
window .onunload = function ()
{
var btn = 文档 .getElementById(btnID);
btn.disabled = false ;
btn.value = btnText;
}
}





在UseSubmitBehaviour设置为false的情况下,包含对disableBtn OnClientClick的调用。



 <   asp:button     id   =  btnSubmit    runat   =  server    onclientclick   =  disableBtn(this.id,'正在提交...')    text   = 提交    usesubmitbehavior   =  False    xmlns:asp   = #unknown    /  >  


hi to all,
Here i need how to avoid multiple click, here i done that process.now need is if i click save validation message show two time.how to avoid that.

coding is:-

script:

function ClientSideClick(myButton) {

            if (typeof (Page_ClientValidate) == 'function')
               {
                if (Page_ClientValidate() == false)
                { return false; }
            }


            if (myButton.getAttribute('type') == 'button') {

                myButton.disabled = true;

            }



button is:-

<asp:Button ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert"
                                                                                  CssClass="savebutton1231" EnableTheming="false" SkinID="skinBtnSave" onclientclick="ClientSideClick(this)" UseSubmitBehavior="false" OnClick="InsertButton_Click"></asp:Button>





i need how to avoid same validation message twice.

解决方案

if using an updatepanel you can grey out the screen once the client clicks the button using css. this will prevent a secondary click.

<ProgressTemplate>
<div class="divWaiting">



.divWaiting{
position: absolute;
background-color: black;
z-index: 2147483647 !important;
opacity: 0.6;
overflow: hidden;
text-align: center; top: 0; left: 0;
height: 100%;
width: 100%;
padding-top:20%;
}


I have used the solution below with success. I had gotten this script from a co-worker of mine. It uses JavaScript functions to disable and enable the button. While disable it also sets the button image to a .gif to indicate processing.

Forgive me if this was already posted as a solution on another thread.

function disableBtn(btnID, newText) {
    //initialize to avoid 'Page_IsValid is undefined' JavaScript error
    Page_IsValid = null;
    //check if the page request any validation   
    // if yes, check if the page was valid
    if (typeof (Page_ClientValidate) == 'function') {
        Page_ClientValidate();
        //you can pass in the validation group name also
    }
    //variables
    var btn = document.getElementById(btnID);
    var isValidationOk = Page_IsValid;
    /********NEW UPDATE************************************/   
    //if not IE then enable the button on unload before redirecting/ rendering   
    if (navigator.appName !== 'Microsoft Internet Explorer')
    {
           EnableOnUnload(btnID, btn.value);   
    }   
    /***********END UPDATE ****************************/   
    // isValidationOk is not null
    if (isValidationOk !== null) {
        //page was valid
        if (isValidationOk) {
            btn.disabled = true;
            btn.value = newText;
            btn.style.background = 'url(~/images/ajax-loader.gif)';
        }
        else {//page was not valid
            btn.disabled = false;
        }
    }
    else {//the page don't have any validation request
        setTimeout("setImage('"+btnID+"')", 10);
        btn.disabled = true;
        btn.value = newText;
    }
}

//set the background image of the button
function setImage(btnID) 
{
    var btn = document.getElementById(btnID);
    btn.style.background = 'url(images/loading.gif)';
}

//enable the button and restore the original text value
function EnableOnUnload(btnID, btnText)
{
    window.onunload = function()
    {
            var btn = document.getElementById(btnID);
            btn.disabled = false;
            btn.value = btnText;
    }
}



Include a call to disableBtn OnClientClick with UseSubmitBehaviour set to false.

<asp:button id="btnSubmit" runat="server" onclientclick="disableBtn(this.id, 'Submitting...')" text="Submit" usesubmitbehavior="False" xmlns:asp="#unknown" />


这篇关于如何避免使用脚本在asp.net中的formview中单击多个按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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