Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何从代码隐藏中显示引导弹出框?_C#_Asp.net_Bootstrap Popover - Fatal编程技术网

C# 如何从代码隐藏中显示引导弹出框?

C# 如何从代码隐藏中显示引导弹出框?,c#,asp.net,bootstrap-popover,C#,Asp.net,Bootstrap Popover,我有一个按钮,可以打开引导弹出窗口。这是标记 <HeaderStyle Width="6%"></HeaderStyle> <ItemTemplate> <asp:LinkButton runat="server" ID="button1" data-toggle="popover" CssClass="btn btn-primary" Text="Button1" /> </ItemTemplate

我有一个按钮,可以打开引导弹出窗口。这是标记

 <HeaderStyle Width="6%"></HeaderStyle>
      <ItemTemplate>
        <asp:LinkButton runat="server" ID="button1" data-toggle="popover" CssClass="btn btn-primary" Text="Button1" />
      </ItemTemplate>
目的是显示代码隐藏/服务器端代码中的引导弹出框。这是我从代码中尝试的,但它不起作用

C#


任何建议都将不胜感激

听起来像是显示
popover
的代码没有执行,因为当试图调用
RegisterStartupScript
方法中的
popover('show')
函数时,jQuery库可能尚未加载或未处于
ready
状态。尝试将该函数调用包装到
文档中。就绪
块:

string script = "$(function() { $('#testDiv').popover('show'); });"

ScriptManager.RegisterStartupScript(this, GetType(), "popoverscript", script, true);
注意:还要确保
$('[data toggle=“popover”]').popover(…)
定义已经包装在
文档中。如果
popover
仍然没有显示,则准备好
阻止

类似问题:


为了澄清我们找到的解决方案:

这是一个时间问题。我们试图用JavaScript初始化弹出窗口。我们曾这样说:

$('[data-toggle="popover"]').popover({
    placement: 'left',
    trigger: 'click',
    html: true,
    content: $('#testDiv')
  });
调用
Sys.Application.add\u load()
的内部。问题是,当我们从服务器显示popover时,popover尚未初始化,因为客户端上的任何内容都将在服务器完成后执行。解决方案是将初始化和调用移动到服务器端按钮单击事件处理程序的内部,以确保它们已初始化,然后以正确的顺序显示

在按钮事件中,C#:


谢谢你的建议。是的,我完全同意你的观点。我们解决了这个问题。jquery(popover)中的内容没有处于就绪状态/没有像您提到的那样初始化。我的同事@JBizzle提出了解决方案。我将在下一条评论中发布解决方案。
ScriptManager.RegisterStartupScript(此,GetType(),“popoverscript”,“$”(“#“+button.ClientID+”)).popover({html:true,内容:$(“#actionButtonDiv”),容器:'body',触发器:'focus位置:'left'}),true);                                                                                              ScriptManager.RegisterStartupScript(this,GetType(),“show”,“$”(“#“+button.ClientID+”).popover('show');”,true)
string script = "$(function() { $('#testDiv').popover('show'); });"

ScriptManager.RegisterStartupScript(this, GetType(), "popoverscript", script, true);
$('[data-toggle="popover"]').popover({
    placement: 'left',
    trigger: 'click',
    html: true,
    content: $('#testDiv')
  });
ScriptManager.RegisterStartupScript(this, GetType(), "popoverscript", "$('#" + 
button.ClientID + "').popover({ html: true, content: $('#actionButtonDiv'), 
container: 'body', trigger: 'focus', placement: 'left'});", true); 

ScriptManager.RegisterStartupScript(this, GetType(), "show", "$('#" + button.ClientID 
+ "').popover('show');", true);