简体   繁体   English

使用具有Bootstrap模态的asp.net Webform ValidationSummary

[英]Using an asp.net webform ValidationSummary with bootstrap modal

I am trying to do some styling on my page, and I really would like to implement the built -in modal that bootstrap has for displaying my ValidationSummary control, along with any other messages I may want. 我正在尝试在页面上进行一些样式设置,我真的很想实现引导程序用于显示ValidationSummary控件以及我可能需要的其他任何消息的内置模式。 So far, I can get the modal to pop up, but the button never reaches my OnClick method, and it does not display the validation summary. 到目前为止,我可以弹出模式对话框,但是该按钮从未到达我的OnClick方法,并且它不显示验证摘要。 I assume this has something to do with posting, and I was wondering if there is a way around this, and if I can still implement the modal? 我认为这与发布有关,我想知道是否有解决方法,是否仍然可以实现模式?

My page looks something like this currently: 我的页面当前看起来像这样:

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="Server">
    <script>
        //MODAL SCRIPT
        $('#myModal').on('shown.bs.modal', function () {
            $('#myInput').focus()
        })
    </script>


...


<!-- PROGRAM NAME -->
                    <p>
                        <asp:Label ID="ProgramName_Label" runat="server" Text="Program Name:" CssClass="label-program"></asp:Label>
                        <asp:TextBox ID="ProgramName" runat="server" class="form-control text-fix"></asp:TextBox>
                    </p>

                    <asp:RequiredFieldValidator ID="ProgramNameValidator" runat="server" ErrorMessage="Program Name is required." ControlToValidate="ProgramName"></asp:RequiredFieldValidator>

...

 <!-- SUBMIT BUTTON -->
        <div class="col-md-12" align="center">
            <asp:LinkButton ID="SubmitProgram" runat="server" OnClick="SubmitProgram_Click" 
                CssClass="listview-buttons"  Font-Underline="false" data-toggle="modal"
                data-target="#myModal">Submit Program</asp:LinkButton>
        </div>

        <!-- BOOTSTRAP MODAL DIALOG -->
        <div id="myModal" class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
            <div class="modal-dialog modal-lg">
                <div class="modal-content">
                    <div class="modal-body">
                        <asp:ValidationSummary ID="ValidationSummary1" runat="server" />
                        <asp:Label ID="ValidationList" runat="server"></asp:Label>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                    </div>
                </div>
            </div>
        </div>

All you have to do is to add this function on your page: 您要做的就是在页面上添加此功能:

   function WebForm_OnSubmit() {
            if (typeof (ValidatorOnSubmit) == "function" && ValidatorOnSubmit() == false) {
                $('#myModal').modal('show');
                return false;
            }
            return true;
        }

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

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