[CLOSED] How to call one procedure (code behinde) from javascript

  1. #1

    [CLOSED] How to call one procedure (code behinde) from javascript

    Hi Support Team,

    Need your help and info about how to execute a procedure in code behind from javascript:

    <%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm1.aspx.vb" Inherits="Test.WebForm1" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>test</title>
        <script type="text/javascript">
            var Confirm = function () {
                var title = 'Confirm';
                var msg = 'Are you sure?';
    
                Ext.Msg.confirm(title, msg, function (btn) {
                    if (btn == 'yes') {
                       deleteselected();
                        return true;
                    } else {
                        return false;
                    }
                });
            }
    </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <ext:ResourceManager ID="ResourceManager1" runat="server" EnableViewState="True" DisableViewState="False" />
            <ext:Button ID="buttonSave" runat="server" Text="Save" Icon="Disk" >
            <Listeners>
                <Click Handler="return Confirm();" />
            </Listeners>
            </ext:Button>
        </div>
        </form>
    </body>
    </html>

    in code behind:
    Public Class WebForm1
        Inherits System.Web.UI.Page
    
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    
        End Sub
    
        Public Sub deleteselected()
            Response.Redirect("~/WebForm2.aspx")
        End Sub
    
    End Class
    Need your help please. thanks.

    Regards,
    @joe2014
    Last edited by geoffrey.mcgill; Sep 26, 2014 at 4:17 PM. Reason: CLOSED
  2. #2
    Hello,

    Use of a DirectMethod should help, see samples in the Examples Explorer:

    https://examples2.ext.net/#/search/directmethods
    Geoffrey McGill
    Founder
  3. #3
    Thanks Geoffrey,

    I revised the code like these:

    <%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm1.aspx.vb" Inherits="Test.WebForm1" %>
    
    <script runat="server">
        <DirectMethod>
        public sub SetTimeStamp()
            open_page()
        End Sub
    </script>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>test</title>
        <script type="text/javascript">
            var Confirm = function () {
                var title = 'Confirm';
                var msg = 'Are you sure?';
    
                Ext.Msg.confirm(title, msg, function (btn) {
                    if (btn == 'yes') {
                        SetTimeStamp();
                        return true;
                    } else {
                        return false;
                    }
                });
            }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <ext:ResourceManager ID="ResourceManager1" runat="server" EnableViewState="True" DisableViewState="False" />
            <ext:Button ID="button2" runat="server" Text="Test1" Icon="Disk" >
            <Listeners>
                <Click Handler="return Confirm();" />
            </Listeners>
            </ext:Button>
        </div>
        </form>
    </body>
    </html>
    and the code behind are:
    Imports Ext.Net
    
    Public Class WebForm1
        Inherits System.Web.UI.Page
    
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    
        End Sub
    
        Public Sub open_page()
            Response.Redirect("~/WebForm2.aspx")
        End Sub
    
    End Class
    But still didn't work. need your advise please. thanks.

    joe2014
  4. #4

    Its work

    Hi Geoffrey,

    Finally, I found the way to solved it. thanks a lot for your info.

    here the solutions , hope another member can see this codes:

    <%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm1.aspx.vb" Inherits="Test2.WebForm1" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
      
     <script runat="server">
         <DirectMethod>
         Protected Sub Confirm(ByVal sender As Object, ByVal e As EventArgs)
             'Ext.Net.X.MessageBox.Confirm("Test", "Are you sure?").Show()
    
             Dim myButtons As Ext.Net.MessageBoxButtonsConfig = New Ext.Net.MessageBoxButtonsConfig
    
             myButtons.Yes = New Ext.Net.MessageBoxButtonConfig
             myButtons.No = New Ext.Net.MessageBoxButtonConfig
             
             myButtons.Yes.Handler = "#{DirectMethods}.DoYes()"
             myButtons.Yes.Text = "Yes"
             
             myButtons.No.Handler = "#{DirectMethods}.DoNo()"
             myButtons.No.Text = "No"
             
             
             Ext.Net.X.MessageBox.Confirm("Test", "Are you sure?", myButtons).Show()
         End Sub
         
         <DirectMethod()>
         Public Sub DoYes()
             Ext.Net.X.Msg.Alert("DirectMethod", "DoYes").Show()
         End Sub
    
         <DirectMethod>
         Public Sub DoNo()
             Ext.Net.X.Msg.Alert("DirectMethod", "DoNo").Show()
         End Sub
    
         
     </script>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <ext:ResourceManager ID="ResourceManager1" runat="server" />
            <ext:Button ID="Button1" runat="server" Text="Confirm" OnDirectClick="Confirm" />
        </div>
        </form>
    </body>
    </html>
    Thanks.

    Regards,
    Joe

Similar Threads

  1. [CLOSED] Invalid procedure call or argument
    By wisdomchuck in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Apr 06, 2012, 6:13 PM
  2. How to call the javascript function form code behind
    By harshad.jadhav in forum 1.x Help
    Replies: 3
    Last Post: Mar 29, 2011, 3:00 PM
  3. help for a beginner! as a procedure call ?
    By julioc_m18 in forum 1.x Help
    Replies: 6
    Last Post: Feb 09, 2011, 11:49 PM
  4. how to get a grid record in code behinde
    By pearl in forum 1.x Help
    Replies: 3
    Last Post: Nov 10, 2009, 1:24 AM
  5. handling images in code behinde
    By pearl in forum 1.x Help
    Replies: 8
    Last Post: Sep 03, 2009, 3:26 AM

Tags for this Thread

Posting Permissions