PDA

View Full Version : [CLOSED] How to call one procedure (code behinde) from javascript



joe2014
Sep 26, 2014, 1:53 PM
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

geoffrey.mcgill
Sep 26, 2014, 1:58 PM
Hello,

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

http://examples2.ext.net/#/search/directmethods

joe2014
Sep 26, 2014, 2:31 PM
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

joe2014
Sep 26, 2014, 3:17 PM
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