Turgay ACAR
Turgay ACAR

Reputation: 33

Jquery modal with code behind

I have a problem. side code behind in asp.net I want to run with the modal popup with the following code. But I was not quite successful in my research.

How do you think I should implement a process?

<script type="text/javascript">
    function showAjaxModal() {
        jQuery('#Modal_Alert').modal('show', { backdrop: 'static' });

    }
</script>
<div class="modal fade" id="Modal_Alert">
    <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">
                    <asp:Label runat="server" ID="LblAlertHeader"></asp:Label></h4>
            </div>

            <div class="modal-body">
                <asp:Label runat="server" ID="LblAlertBody"></asp:Label>
            </div>

            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Kapat</button>
                <%--<button type="button" class="btn btn-info">Save changes</button>--%>
            </div>
        </div>
    </div>
</div>

I want to do

if (true)
        {
            //open modal
        }
        else
        {
            //open modal
        }

code is running this

<a href="javascript:;" onclick=" showAjaxModal(); " class="btn btn-default" >Show Me</a>

But not work code behind.

protected void BtnKaydet_Click(object sender, EventArgs e)
    { //openmodal; }

Please help.

Upvotes: 1

Views: 847

Answers (2)

JAIGANESH
JAIGANESH

Reputation: 87

Use the below code it will work

                <script type="text/javascript">
                    function showAjaxModal() {
                       jQuery('#Modal_Alert').modal('show', { backdrop: 'static' });
                       return false;

                    }
                </script>
                 <asp:Button ID="BtnKaydet" runat="server" UseSubmitBehavior="false" OnClientClick="return showAjaxModal();" />

Upvotes: 1

Mairaj Ahmad
Mairaj Ahmad

Reputation: 14624

Add this on button click in code behind

ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "key", "showAjaxModal()", true);

Upvotes: 1

Related Questions