Click here to Skip to main content
12,953,937 members (50,230 online)
Rate this:
 
Please Sign up or sign in to 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:

<%@ 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 :

protected void btn_Click(object sender, EventArgs e)
    {
        ScriptManager.RegisterClientScriptBlock(this, GetType(), "Sc", "jqcall();", true);
 
    }
Posted 25-Jul-13 20:16pm
Rockstar_5.7K
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

test the following code :

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 :

$(document).ready(function($){
   alert('jquery is ok ');
});
  Permalink  
v5
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Try the following:

protected void btn_Click(object sender, EventArgs e)
{
    Page.ClientScript.RegisterStartupScript(this.GetType(), "Sc", "jqcall();", true);
}
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

Hi,

Script :
<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);
  Permalink  

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

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 6,464
CHill60 3,490
Maciej Los 3,123
ppolymorphe 2,020
Jochen Arndt 1,975


Advertise | Privacy | Mobile
Web02 | 2.8.170525.1 | Last Updated 26 Jul 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100