Twitter bootstrap 从代码隐藏打开引导模式

Twitter bootstrap 从代码隐藏打开引导模式,twitter-bootstrap,modal-dialog,Twitter Bootstrap,Modal Dialog,有人知道如何从代码隐藏中打开twitter引导模式吗 我想在保存时打开基于某个请求的模式。类似于“嘿,没有股票,选择以下选项之一继续(放弃,保留…)并按下该按钮(可能会为继续进行回发)” 我正在使用ASP.NET web表单。这样做怎么样: 1) 用表单显示弹出窗口 2) 使用AJAX提交表单 3) 在AJAX服务器端代码中,呈现以下响应之一: 显示带有验证或消息的窗体弹出窗口 关闭弹出窗口(可能会将您重定向到新页面) 最后我发现了阻止我从代码隐藏中显示模式的问题。 人们一定会认为,注册一个c

有人知道如何从代码隐藏中打开twitter引导模式吗

我想在保存时打开基于某个请求的模式。类似于“嘿,没有股票,选择以下选项之一继续(放弃,保留…)并按下该按钮(可能会为继续进行回发)”


我正在使用ASP.NET web表单。

这样做怎么样:

1) 用表单显示弹出窗口

2) 使用AJAX提交表单

3) 在AJAX服务器端代码中,呈现以下响应之一:

  • 显示带有验证或消息的窗体弹出窗口
  • 关闭弹出窗口(可能会将您重定向到新页面)

最后我发现了阻止我从代码隐藏中显示模式的问题。 人们一定会认为,注册一个clientscript作为开场白是很容易的,比如:

ScriptManager.RegisterClientScriptBlock(this, this.GetType(),"none",
    "<script>$('#mymodal').modal('show');</script>", false);
ScriptManager.RegisterClientScriptBlock(this,this.GetType(),“无”,
“$('mymodal').modal('show');”,false);
但这对我从来都不起作用

问题是,当模式位于asp:Updatepanel中时,推特引导模式脚本根本不起作用。 情态动词的行为从每一方都失败了,从codebehind到client,从client到codebehind(回发)。它甚至可以在模式的任何js执行时防止回发,比如关闭按钮,您还需要处理一些服务器对象(例如脏的示例)

我已经通知了bootstrap的工作人员,但他们很方便地回答说:“请给我们一个只有纯html而不是asp的失败场景。” 在我的镇上,那叫。。。好吧,Bootstrap不支持比普通html更多的东西。不用担心,在asp上使用它

我想他们至少应该看看他们在后台管理方面的不同,我发现这是问题的主要原因,但是。。。(这里只是一个提示)

因此,任何有问题的人都可以放下updatepanel试试。

供参考


我以前在jQuery小部件中见过这种奇怪的行为。部分关键是将updatepanel放在模式中。这允许updatepanel的DOM“停留在”模式中(但是它可以与引导一起工作)。

默认情况下,引导javascript文件包含在关闭主体标记之前

        <script src="vendors/jquery-1.9.1.min.js"></script>
        <script src="bootstrap/js/bootstrap.min.js"></script>
        <script src="vendors/easypiechart/jquery.easy-pie-chart.js"></script>
        <script src="assets/scripts.js"></script>
 </body>

这种打开模态的方法不会为我显示模态。我发现这是一件自命不凡的作品

我删除了:

 ScriptManager.RegisterStartupScript(this,this.GetType(),"Pop", "openModal();", true);
然后,我在代码隐藏调用中添加了一个名为lblJavaScript的asp:label:

lblJavaScript.Text = "<script language=\"JavaScript\">openModal()</script>";
lblJavaScript.Text=“openModal()”;

现在将显示模式。

也许这个答案太晚了,但它很有用。
为此,我们有3个步骤:
1-在HTML中创建模态结构。
2-创建一个按钮以调用java脚本中的函数,打开模式并在CSS中设置
display:none

3-通过代码隐藏中的函数调用此按钮。
您可以在下面的代码段中看到这些步骤:

HTML模式:

<div class="modal fade" id="myModal">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                <span aria-hidden="true">&times;</span></button>
                            <h4 class="modal-title">
                                Registration done Successfully</h4>
                        </div>
                        <div class="modal-body">
                            <asp:Label ID="lblMessage" runat="server" />
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">
                                Close</button>
                            <button type="button" class="btn btn-primary">
                                Save changes</button>
                        </div>
                    </div>
                    <!-- /.modal-content -->
                </div>
                <!-- /.modal-dialog -->
            </div>
            <!-- /.modal -->  

此解决方案是我使用过的任何解决方案之一。

上面的所有示例都应该有效—只需添加一个文档就绪操作,并更改文本更新的执行顺序,同时确保使用脚本管理器或其他方法对您有效。下面是代码背后的文本

aspx


这行代码为我打开了引导模式代码

ScriptManager.RegisterStartupScript(Page, Page.GetType(), "randomText", "$(document).ready(function () {$('#myModal').modal();});", true);

您使用的服务器端技术是什么,asp.net?你是说你想显示模式的页面后面的代码吗?对不起,我编辑了这个问题以便更清楚。没有人知道为什么“ClientScript.RegisterClientScriptBlock([GetType],“none”,“$('#MyModal')。show();”,True)“不起作用??谢谢你的回答,这不是一个明确的验证,但是你说的就行了。不管怎么说,当你说:“用表单显示弹出窗口”和“关闭弹出窗口”是的,这些都是我的问题,从codebehind打开和关闭。这只是为我节省了许多行代码。我正在使用asp:hidden字段并在隐藏字段中设置值。加载页面时,我会计算隐藏字段,以确定js是否应该弹出打开对话框。谢谢你。我有一些清洁工作要做!在“lblEdit_Click”事件中,我在intellisense中没有“ScriptManager”选项。我意识到这是一个非常古老的线程,我希望有一个解决办法。我找到了自己的解决方案:解决方案:确保使用System.Web.UI;正在被引用。这对我有用,但屏幕会闪烁一秒钟,然后出现下拉列表。有没有办法摆脱闪烁?使用VS2019…我所做的就是把JS放在ASP页面的底部,把RegisterStartupScript放在代码后面。就这样。
<div class="modal fade" id="myModal">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                <span aria-hidden="true">&times;</span></button>
                            <h4 class="modal-title">
                                Registration done Successfully</h4>
                        </div>
                        <div class="modal-body">
                            <asp:Label ID="lblMessage" runat="server" />
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">
                                Close</button>
                            <button type="button" class="btn btn-primary">
                                Save changes</button>
                        </div>
                    </div>
                    <!-- /.modal-content -->
                </div>
                <!-- /.modal-dialog -->
            </div>
            <!-- /.modal -->  
<button type="button" style="display: none;" id="btnShowPopup" class="btn btn-primary btn-lg"
                data-toggle="modal" data-target="#myModal">
                Launch demo modal
            </button>    
<script type="text/javascript">
        function ShowPopup() {
            $("#btnShowPopup").click();
        }
    </script>  
protected void Page_Load(object sender, EventArgs e)
{
    ClientScript.RegisterStartupScript(this.GetType(), "alert", "ShowPopup();", true);
    this.lblMessage.Text = "Your Registration is done successfully. Our team will contact you shotly";
}  
<div class="modal fade" id="myModal" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <asp:UpdatePanel ID="upModal" runat="server" ChildrenAsTriggers="false" UpdateMode="Conditional">
                <ContentTemplate>
                    <div class="modal-content">
                        <div class="modal-header">
                            <h4 class="modal-title"><asp:Label ID="lblModalTitle" runat="server" Text=""></asp:Label></h4>
                            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                        </div>
                        <div class="modal-body">
                            <asp:Label ID="lblModalBody" runat="server" Text=""></asp:Label>
                        </div>
                        <div class="modal-footer">
                            <button class="btn btn-primary" data-dismiss="modal" aria-hidden="true">Close</button>
                        </div>
                    </div>
                </ContentTemplate>
            </asp:UpdatePanel>
        </div>
    </div>
lblModalTitle.Text = "Validation Errors";
lblModalBody.Text = form.Error;
upModal.Update();
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "myModal", "$(document).ready(function () {$('#myModal').modal();});", true);
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "randomText", "$(document).ready(function () {$('#myModal').modal();});", true);