Open popup with linkbutton

假装没事ソ 提交于 2019-12-08 11:14:42

问题


I am using bootstrap modal popup, and this div is (FOR EXAMPLE) a popup [using a repeater]

<div id="messageContent">Hello World!</div>

This pop-up can be opened by doing this (this works):

<a href="#messageContent" role="button" class="btn" data-toggle="modal">Open Popup</a>

But I want to pass some DataBinder.Eval-values with the <a href=""></a>, and this is not possible, so this is what I tried with a linkbutton:

<asp:LinkButton ID="lbOpenMessage" runat="server" CommandName="OpenMessage" CommandArgument='<%#Eval("MessageID")%>'>Open Popup</asp:LinkButton>

But I am not abled to call the <a href="#messageContent"></a> in the linkbutton to open the pop-up.

When I do something like this:

<asp:LinkButton ID="lbOpenMessage" runat="server" CommandName="OpenMessage" CommandArgument='<%#Eval("MessageID")%>'>
<a href="#messageContent" role="button" class="btn" data-toggle="modal">Open Popup</a>
</asp:LinkButton>

Then the e.Commandname-event doesn't get fired, so I don't get the MessageID.

What can I do to open the pop-up with <a href="#messageContent"></a>, with passing the DataBinder.Eval-values?

I did some research, but couldn't find anything.


回答1:


You need to show the modal via a javascript call as opposed to the markup shortcuts. refer here http://getbootstrap.com/javascript/#modals

the function you want to call is $('#myModal').modal(options)

So in your item command event you want the following:

if (e.commandname == "yourcommandname")
{
    // do your stuff that needs to be done
    ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "key", " $('#myModal').modal(options);", true);
}


来源:https://stackoverflow.com/questions/17823056/open-popup-with-linkbutton

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!