This is a migrated thread and some comments may be shown as answers.

Calling Jquery from Button

3 Answers 168 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 23 Nov 2011, 11:16 PM
Hi, I have a jquery modal popup on my page.

I can open it fine with a regular asp.net button
<asp:Button ID="btnQuery" OnClientClick="showDialog('newRecord');return false;" runat="server" Text="Open Modal" />

but i cannot open it using the RadButton
<telerik:RadButton ID="btnOpen" runat="server" Text="Open Modal" onclientclicked="showDialog('newRecord');return false;"></telerik:RadButton>

I am not sure what I am doing wrong here. 
Thanks for any assistance

3 Answers, 1 is accepted

Sort by
0
Stuart Hemming
Top achievements
Rank 2
answered on 24 Nov 2011, 12:51 AM
Michael,

You want something like this ...
<telerik:RadButton ID="btnOpen" runat="server" Text="Open Modal" onclientclicked="showDialog;" CommandName="newRecord" AutoPostBack="false"></telerik:RadButton>

Then in your javascript code, modify you showDialog function something like this...
function showDialog(sender, e)
{
  var arg = e.get_commandName();
  // Your original function code goes here.
}

Obviously, if your showDialog method only ever does the one thing, you don't need to bother with the command argument.

-- 
Stuart

0
Michael
Top achievements
Rank 1
answered on 24 Nov 2011, 03:32 AM
Thanks for you response.  I have tried this and could still not get it to work.
I have provided all code this time.

------------------------------------------------------------------------------
Original Method (Working but not with a Telerik Button)

<asp:Button ID="btnQuery" OnClientClick="showDialog('newRecord');return false;" runat="server" Text="Open Modal" />
 
 function showDialog(id) {
         $('#' + id).dialog("open");
     }

     function closeDialog(id) {
         $('#' + id).dialog("close");
     }    
                     

------------------------------------------------------------------------------
Suggest Method (Could not get this to work)

 <telerik:RadButton ID="btnOpen" runat="server" Text="Open Modal" onclientclicked="showDialog;" CommandName="newRecord" AutoPostBack="false"></telerik:RadButton>

     function showDialog(sender, e) {
         var arg = e.get_commandName();
         $('#' + arg).dialog("open");
     }

     function closeDialog(sender, e) {
         var arg = e.get_commandName();
         $('#' + arg).dialog("open");
     }    


------------------------------------------------------------------------------
// Jquery Window
$(document).ready(function () {
$('#newRecord').dialog({
             autoOpen: false,
             modal: true,
             draggable: true,
             resizable: false,
             width: 1000,
             height: 600,
             title: "Create SMS",
             open: function (type, data) {
                 $(this).parent().appendTo("form");
             }
         });
});

Thanks Again
0
Stuart Hemming
Top achievements
Rank 2
answered on 25 Nov 2011, 07:30 AM
Michael,

I can't speak to the dialog plugin you have; I have no idea which it is, however, the following code does work....
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication2.WebForm1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1"
              runat="server">
            <telerik:RadScriptManager runat="server"
                                      ID="RadScriptManager1"></telerik:RadScriptManager>
            <telerik:RadScriptBlock runat="server"
                                    ID="RadScriptBlock1">
                <script type="text/javascript">
                    function showDialog(sender, e)
                    {
                        var cmd = e.get_commandName();
                        radalert("Command was '" + cmd + "'", 200, 100, "Information");
                    }
                </script>
            </telerik:RadScriptBlock>
            <telerik:RadButton runat="server"
                               ID="RadButton1"
                               AutoPostBack="false"
                               Text="OpenModal"
                               OnClientClicked="showDialog"
                               CommandName="NewRecord"></telerik:RadButton>
            <telerik:RadWindowManager runat="server"
                                      ID="RadWindowManager1"
                                      Modal="true"></telerik:RadWindowManager>
        </form>
    </body>
</html>

Try this. If it works but substituting your dialog plugin for the radalert call doesn't then you may need to look to that.

Hope this helps.

-- 
Stuart
Tags
General Discussions
Asked by
Michael
Top achievements
Rank 1
Answers by
Stuart Hemming
Top achievements
Rank 2
Michael
Top achievements
Rank 1
Share this question
or