twitter-bootstrap 在 ASP.NET 中单击链接按钮时如何在 Bootstrap Modal 中显示数据

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22432579/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 20:18:34  来源:igfitidea点击:

How to display data in Bootstrap Modal when link button click in ASP.NET

c#asp.nettwitter-bootstraptwitter-bootstrap-3

提问by Srinivas

How to display data in Bootstrap Modal when link button click in ASP.NET. In my code When i click on link button Modal is opening, but assign values are not displaying. Please tell me how to display modal with assigned values. Thanks.

在 ASP.NET 中单击链接按钮时如何在 Bootstrap Modal 中显示数据。在我的代码中,当我单击链接按钮时,模态正在打开,但未显示分配值。请告诉我如何显示具有指定值的模态。谢谢。

.aspx Code:

.aspx 代码:

  <asp:LinkButton ID="linkButton8" runat="server" data-toggle="modal" data-target="#myModal" OnClick="linkButton_Click">CIS Information</asp:LinkButton>

      <div class="modal" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                            <h4 class="modal-title" id="myModalLabel" align="center">Candidate Information Sheet</h4>
                        </div>
                        <div class="modal-body">

                            <table class="table table-bordered" align="center">
                                <tr>
                                    <td>Name</td>
                                    <td>
                             <asp:TextBox ID="txtName" runat="server"></asp:TextBox></td>
                                    <td>Email</td>
                                    <td>
                                        <asp:TextBox ID="txtEnail" runat="server"></asp:TextBox></td>
                                </tr>
                            </table>
                        </div>
                        <div class="modal-footer">
                      <button type="button" class="btn btn-primary">Save</button>
                <button type="button" class="btn btn-primary" data-ismiss="modal">Close</button>
                        </div>
                    </div>
                </div>
            </div>

C# Code:

C# 代码:

 protected void linkButton_Click(object sender, EventArgs e)
        {
            txtName.Text = "Name";
            txtEnail.Text = "[email protected]";
        }

回答by Haitham Shaddad

Remove the data-toggle and update the code behind to be like this:

删除数据切换并更新后面的代码如下:

 protected void linkButton_Click(object sender, EventArgs e)
        {
            txtName.Text = "Name";
            txtEnail.Text = "[email protected]";
            Page.ClientScript.RegisterStartupScript(GetType(), "modelBox", "$("#myModal").modal('show');", true);
        }

It is better though to make the link button has a client side click event that gets the data through ajax, set the textboxs values and use the same modal('show')JavaScript function to display the modal box, this will be more efficient and user friendly.

最好让链接按钮有一个客户端点击事件,通过ajax获取数据,设置文本框值并使用相同的modal('show')JavaScript函数来显示模态框,这样会更高效和用户友好。

回答by The Mahahaj

Try adding UseSubmitBehavior="false" and using an asp:button instead.

尝试添加 UseSubmitBehavior="false" 并改用 asp:button。

    <asp:Button ID="btnModal" runat="server" data-toggle="modal" data-target="#myModal" OnClick="linkButton_Click" UseSubmitBehavior="false">CIS Information</asp:Button>

The UseSubmitBehavior attribute determines whether the Button uses the browsers submit functionality or ASP.NET postback. By default it is set to true.

UseSubmitBehavior 属性确定按钮是使用浏览器提交功能还是 ASP.NET 回发。默认情况下,它设置为 true。

Edit

编辑

Due to linkButton not having the "UseSubmitBehavior" property.

由于 linkBut​​ton 没有“UseSubmitBehavior”属性。