Markup
<ext:Button ID="Button1" runat="server" Icon="ShapeSquare" Text="Submit" OnClick="GreetingBtn_Click" >
</ext:Button>
Codebehind
public void GreetingBtn_Click(Object sender, EventArgs e)
{
Response.Redirect("www.google.lk");
}
In this scenario, I would like to be able to execute the ASP.net event handler on the Ext.net button click. How to achieve this functionality?
From examples :
Markup
<ext:Button
ID="Button1"
runat="server"
Text="Click Me"
OnDirectClick="ButtonClick" />
Code behind
protected void ButtonClick(object sender, DirectEventArgs e)
{
Response.Redirect("www.google.lk");
}
There are a couple issues with your original code sample:
EventArgs
parameter in your ButtonClick
Method should be DirectEventArgs
. OnClick
property configured on the <ext:Button>
instance should be renamed to OnDirectClick
. You can call a server-side Method using either a DirectEvent
handler, or manually calling a DirectMethod
. Both function in a similar way by making an AJAX request back to the page.
The following sample demonstrates both the DirectEvent
and DirectMethod
options.
Example
<%@ Page Language="C#" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<script runat="server">
protected void Button1_Click(Object sender, DirectEventArgs e)
{
X.Msg.Notify("DirectEvent", DateTime.Now.ToLongTimeString()).Show();
}
[DirectMethod]
public void DoSomething()
{
X.Msg.Notify("DirectMethod", "DoSomething was called").Show();
}
</script>
<html>
<head runat="server">
<title>Ext.NET Example</title>
</head>
<body>
<form runat="server">
<ext:ResourceManager runat="server" />
<ext:Button runat="server" Text="DirectEvent">
<DirectEvents>
<Click OnEvent="Button1_Click" />
</DirectEvents>
</ext:Button>
<ext:Button runat="server" Text="DirectMethod">
<Listeners>
<Click Handler="Ext.net.DirectMethods.DoSomething();" />
</Listeners>
</ext:Button>
</form>
</body>
</html>
Hope this helps.
Add the property AutoPostBack="true"
on the Ext.net button.
<Buttons>
<ext:Button ID="Button1" runat="server" Icon="ShapeSquare" AutoPostBack="true" Text="Submit" OnClick="GreetingBtn_Click" >
</ext:Button>
</Buttons>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.