【问题标题】:Use the button defined behind in C# in front bootstrap modal在前面的引导模式中使用 C# 后面定义的按钮
【发布时间】:2015-10-19 14:39:45
【问题描述】:

我写这个是为了在我点击打开模式按钮后显示一个浮动窗口

 <button type="button" class="btn btn-info" data-toggle="modal" data-target="#myModal">Open Modal</button>
    <div id="myModal" class="modal fade" role="dialog">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">&times;</button>
                    <h4 class="modal-title">Modal Header</h4>

                </div>
                <div class="modal-body" id="imghere">
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                </div>
            </div>
        </div>
    </div>

在这个例子中,我用

定义了按钮

 &lt;button type="button" class="btn btn-info" data-toggle="modal" data-target="#myModal"&gt;Open Modal&lt;/button&gt;

现在我在后面的 C# 循环中定义了一个按钮

protected void GenGridView()
    {
        var data = project.ObtainDataDescJSON();
        Title = "show";
        for (int rowCtr = 0; row < data.Num.Count; row++)
        {
            var buttonField = new ButtonField
            {
                ButtonType = ButtonType.Button,
                Text = "Show",
                CommandName = "Display"

            };
            ModelNumFieldsGrid.Columns.Add(buttonField);
            break;
        }
      }

如何在引导模式中使用我在 C# 中定义的这些按钮?我应该如何改变

 &lt;button type="button" class="btn btn-info" data-toggle="modal" data-target="#myModal"&gt;Open Modal&lt;/button&gt;

我应该使用像 get element By ID 这样的东西吗?我对Web开发真的很陌生,请帮助!谢谢

【问题讨论】:

  • 我很难跟上您要完成的工作。
  • 对不起,让我编辑一下
  • 所以 C# 代码是我在后面定义按钮的方式。我想在前面使用引导模式。通过单击我在 C# 中定义的按钮,我希望显示一个浮动对话框窗口。
  • 我只知道如何用html前面定义的按钮来完成浮动窗口。我不知道如何使用 C# 循环后面定义的按钮来做到这一点
  • @jgabb 我加了一些cmets,有用吗?

标签: javascript c# html bootstrap-modal


【解决方案1】:

您可以只使用常规按钮,而不是按钮字段,但无论哪种方式都应该这样做。或者您可以使用 jQuery 查找您添加的所有按钮并以这种方式附加属性(首选)。

protected void GenGridView()
    {
        var data = project.ObtainDataDescJSON();
        Title = "show";
        for (int rowCtr = 0; row < data.Num.Count; row++)
        {
            var buttonField = new ButtonField
            {
                ButtonType = ButtonType.Button,
                Text = "Show",
                CommandName = "Display"

            };

            buttonField.Attributes.Add("data-toggle", "modal");
            buttonField.Attributes.Add("data-target", "#myModal");
            buttonField.CssClass = "btn btn-info";             

            ModelNumFieldsGrid.Columns.Add(buttonField);
            break;
        }
      }

【讨论】:

  • 错误 3“System.Web.UI.WebControls.ButtonField”不包含“属性”的定义,并且没有扩展方法“属性”接受“System.Web.UI”类型的第一个参数。可以找到 WebControls.ButtonField'(您是否缺少 using 指令或程序集引用?) C:\Users\s0043306\Documents\Visual Studio 2013\WebSites\PredictiveModeling\ModelFields.aspx.cs 54 25 PredictiveModeling
  • 感谢您的回复,但我有关于没有扩展方法属性和没有扩展方法 cssClass 的错误
  • 我尝试使用 System.Runtime.CompilerServices.ExtensionAttribute 添加;但是错误说错误2使用命名空间指令只能应用于命名空间; 'System.Runtime.CompilerServices.ExtensionAttribute' 是类型而不是命名空间 C:\Users\s0043306\Documents\Visual Studio 2013\WebSites\PredictiveModeling\ModelFields.aspx.cs 11 7 PredictiveModeling
  • 只使用常规按钮而不是按钮字段。
【解决方案2】:
System.Web.UI.ScriptManager.RegisterStartupScript(this, this.GetType(), "modelBox", "$('#myModal').modal('show');", true);

【讨论】:

    猜你喜欢
    • 2015-12-25
    • 1970-01-01
    • 1970-01-01
    • 2014-06-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-12
    • 2021-01-20
    相关资源
    最近更新 更多