May 20, 2015, 9:57 AM
Problem with control and events created code behind
Hello
I want to create a grid from code behind, wit a command column and a direct event launched from the command.
I did not manage to make ti works.
I create an ashx file for grid creation. The grid is well created but only event raised error
By digging into the forum, I found that code that works well :
Continuing serachin I found that post : http://forums.ext.net/showthread.php...erating-errors saying that control as to be recreated each time to make it works.
My problem is that using an ashx file, I will not be able to recreate it each time in the default page load?
Is there anyway to make it works?
Here my own test code that doesn't work:
I want to create a grid from code behind, wit a command column and a direct event launched from the command.
I did not manage to make ti works.
I create an ashx file for grid creation. The grid is well created but only event raised error
By digging into the forum, I found that code that works well :
<%@ Page Language="C#" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
Ext.Net.Button button = new Ext.Net.Button() { Text = "Click me" };
button.DirectEvents.Click.Event += Button_Click;
Ext.Net.Parameter testParam = new Ext.Net.Parameter()
{
Name = "test",
Value = "Hello World",
Mode = ParameterMode.Value
};
button.DirectEvents.Click.ExtraParams.Add(testParam);
this.Form.Controls.Add(button);
}
protected void Button_Click(object sender, DirectEventArgs e)
{
X.Msg.Alert("Button_Click", e.ExtraParams["test"]).Show();
}
</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>Ext.Net Example</title>
</head>
<body>
<form runat="server">
<ext:ResourceManager runat="server" />
</form>
</body>
</html>
Until I change it to that :<%@ Page Language="C#" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!Ext.Net.X.IsAjaxRequest)
{
Ext.Net.Button button = new Ext.Net.Button() { Text = "Click me" };
button.DirectEvents.Click.Event += Button_Click;
Ext.Net.Parameter testParam = new Ext.Net.Parameter()
{
Name = "test",
Value = "Hello World",
Mode = ParameterMode.Value
};
button.DirectEvents.Click.ExtraParams.Add(testParam);
this.Form.Controls.Add(button);
}
}
protected void Button_Click(object sender, DirectEventArgs e)
{
X.Msg.Alert("Button_Click", e.ExtraParams["test"]).Show();
}
</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>Ext.Net Example</title>
</head>
<body>
<form runat="server">
<ext:ResourceManager runat="server" />
</form>
</body>
</html>
Here, the button is not create again when I click on it and I get error message saying control is not observable.Continuing serachin I found that post : http://forums.ext.net/showthread.php...erating-errors saying that control as to be recreated each time to make it works.
My problem is that using an ashx file, I will not be able to recreate it each time in the default page load?
Is there anyway to make it works?
Here my own test code that doesn't work:
<%@ Page Language="vb"%>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<script runat="server">
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim rmagrdEtt1vent As Ext.Net.Column = Ext.Net.X.GetCmp(Of Ext.Net.Column)("rmagrd")
If Not Ext.Net.X.IsAjaxRequest Then
Dim Reader As New ArrayReader
Dim ModelField As New Model
With ModelField
.Fields.Add("a")
.Fields.Add("b")
.Fields.Add("c")
End With
Dim store As New Store
With store
.Model.Add(ModelField)
.Reader.Add(Reader)
.DataSource = Data
.DataBind()
End With
''AddHandler button.DirectEvents.Click.Event, AddressOf Button_Click
Dim testParam As New Ext.Net.Parameter()
testParam.Name = "test"
testParam.Value = "Hello World"
testParam.Mode = ParameterMode.Value
Dim grid As New Ext.Net.GridPanel
Dim cola As New Column
Dim colb As New Column
Dim colc As New Column
Dim commands As New Ext.Net.ImageCommand
Dim params As New Ext.Net.Parameter
With commands
.CommandName = "Detail"
.Icon = Icon.Magnifier
.ToolTip.Text = "Show detail"
End With
With params
.Name = "data"
.Value = "record.data"
.Mode = 0
.Encode = "true"
End With
With cola
.ID = "Col1"
.DataIndex = "a"
.Text = "aaa"
.Width = "70"
.DirectEvents.Command.ExtraParams.Add(testParam)
AddHandler .DirectEvents.Command.Event, AddressOf Button_Click
.Commands.Add(commands)
End With
With colb
.ID = "Col2"
.Text = "bbb"
.DataIndex = "b"
.Width = "100"
End With
With colc
.ID = "Col3"
.Text = "ccc"
.DataIndex = "c"
.Width = "130"
End With
With grid
.ID = "grid"
.Frame = False
.ColumnLines = True
.Header = False
.Title = "grid"
.ColumnModel.Columns.Add(cola)
.ColumnModel.Columns.Add(colb)
.ColumnModel.Columns.Add(colc)
.Store.Add(store)
End With
Me.form.Controls.Add(grid)
End If
End Sub
Public Sub Button_Click(ByVal sender As Object, ByVal e As DirectEventArgs)
Ext.Net.X.Msg.Alert("Button_Click", e.ExtraParams("test")).Show()
End Sub
Private ReadOnly Property Data() As Object
Get
Return New Object() {New Object() {"aaa", "bbb", "ccc"}, New Object() {"aaa", "bbb", "ccc"}, New Object() {"aaa", "bbb", "ccc"}}
End Get
End Property
</script>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form id="form" runat="server">
<ext:ResourceManager runat="server" />
</form>
</body>
</html>