Open popup with linkbutton

2019-06-11 03:52发布

问题:

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);
}