Click here to Skip to main content
15,886,860 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
Hi EveryOne,

I want to dispaly a Jquery message box from code behind. I have tried but it is not displaying a message box. I have checked with keeping a debugger, controlling is coming in the javascript method but not displaying the message box.

Please look into the code once:

XML
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ModalFromCodeBehind.aspx.cs" Inherits="JQUI_ModalFromCodeBehind" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="../Scripts/jquery-2.0.2.js"></script>
    <script src="../Scripts/jquery-ui-1.10.3.min.js"></script>
    <link href="../Content/themes/base/jquery-ui.css" rel="stylesheet" />

        <script type="text/javascript">

        function jqcall() {
            debugger;
            $('#d1').dialog();
            console.log('dialog');
            return false;

        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Button Text="text" runat="server"  id="btn" OnClick="btn_Click"/>

        <div id="d1" style="display:none;" title="Web Synergies">
            Hi, Wel Come to Hello World

        </div>
    </div>
    </form>
</body>
</html>



Server side code to call Javascript function :

C#
protected void btn_Click(object sender, EventArgs e)
    {
        ScriptManager.RegisterClientScriptBlock(this, GetType(), "Sc", "jqcall();", true);

    }
Posted

test the following code :

C#
protected void btn_Click(object sender, EventArgs e)
    {
        ScriptManager.RegisterClientScriptBlock(this, GetType(), "Sc", "alert('OK');", true);
 
    }


Additional,you should use jquery more standard .like this :

JavaScript
$(document).ready(function($){
   alert('jquery is ok ');
});
 
Share this answer
 
v5
Try the following:

C#
protected void btn_Click(object sender, EventArgs e)
{
    Page.ClientScript.RegisterStartupScript(this.GetType(), "Sc", "jqcall();", true);
}
 
Share this answer
 
Hi,

Script :
XML
<script type="text/javascript">

        function ShowDialog() {
            $(function () {
                $('#rangeDialog').text('Hello');
                $('#rangeDialog').dialog({
                    modal: true,
                    width: 500,
                    draggable: true,
                    buttons: {
                        'OK': function () { $(this).dialog('close'); }
                    }
                })
            }).dialog();

        }
</script>


In Code Behind:

ScriptManager.RegisterClientScriptBlock(this, GetType(), "Sc", "ShowDialog();", true);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900