简体   繁体   English

更新面板,确认按钮和更新进度似乎无法一起使用

[英]Update Panel, confirm button and update progress don't seem to work together

At the moment I have no luck trying to get the three of them to work together and i have had only luck with the updatepanel and update progress nothing the confirm button so far. 目前,我没有运气试图让他们三个一起工作,到目前为止,我对updatepanel和更新进度都没有什么希望,但是没有确认按钮。

<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server"> 
            <ContentTemplate>
                <asp:Button ID="btnEnter" runat="server" Text="Update" Width="180" Style="margin-left:157px;" 
                    OnClick="btnEnter_Click"  
                    CssClass="button-success pure-button"/>

                <asp:ConfirmButtonExtender ID="ConfirmButtonExtender1" runat="server"
                    TargetControlID="btnEnter"
                    ConfirmText="Do you want to see submit?"
                    ConfirmOnFormSubmit="false">
                </asp:ConfirmButtonExtender> 
            </ContentTemplate> 
        </asp:UpdatePanel>
        <asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1"> 
            <ProgressTemplate> 
                <div class="overlay"></div>
                <div class="modal">
                <h2>Please Wait.....</h2>
                    <img alt="Loading..." src="/Images/loading.gif" />
                </div>
            </ProgressTemplate>
        </asp:UpdateProgress>

I have used the javascript function confirm before this and have taken it out it was just a onclientclick on the button. 在此之前,我已经使用了javascript函数确认,并将其取出只是一个onclientclick按钮。
OnClientClick="return confirm('Are you sure you want to submit?');" OnClientClick =“返回确认('确定要提交吗?');” but I need to check validation of the page first before asking to submit but I am clueless about it. 但在要求提交之前,我需要先检查页面的有效性,但我对此一无所知。

here's the behind code atm for the button. 这是该按钮的背后代码atm。

protected void btnEnter_Click(object sender, EventArgs e)
    {
        if(Page.IsValid )
        {
        }
    }

You could do this even easier and more efficient using client side like this: 您可以像使用客户端这样更轻松,更高效地执行此操作:

you just need to add onclientclick attribute in your <asp:Button ID="btnEnter" control and remove the <asp:ConfirmButtonExtender ID="ConfirmButtonExtender1" from your code. 您只需要在<asp:Button ID="btnEnter"控件中添加onclientclick属性, <asp:ConfirmButtonExtender ID="ConfirmButtonExtender1"从代码中删除<asp:ConfirmButtonExtender ID="ConfirmButtonExtender1"

it would be look like this then : 然后看起来像这样:

  <asp:Button ID="btnEnter" runat="server" Text="Update" Width="180" Style="margin-left:157px;" OnClick="btnEnter_Click" CssClass="button-success pure-button" OnClientClick="return confirm('Do you want to see submit?');"/> 

and that's it! 就是这样!

So you DO NOT need asp:ConfirmButtonExtender anymore. 所以,你不需要 asp:ConfirmButtonExtender了。

UPDATE 1 更新1

If you require to check the condition first on the code behind then you could use the code below: 如果您需要先检查后面的代码中的条件,则可以使用以下代码:

  protected void btnEnter_Click(object sender, EventArgs e) { if(Page.IsValid ) { ScriptManager.RegisterStartupScrip(UpdatePanel1, this.GetType(), "confirm", "return confirm('Are you sure you want to submit?');", true); } } 

try to Validate your form using jquery then throw the confirmation dialog if the valiation succeeded . 尝试使用jquery验证表单,如果验证成功,则抛出确认对话框。

function ValidateForm(){
    //validation

    if(succeeded){
    return confirm('are you sure?');
   }else{
     return false
    }
}


$(document).ready(function(){
   $('#' + '<%= btnEnter.ClientID %>').click(function(){
    return ValidateForm();
   });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM