PDA

View Full Version : [CLOSED] OnDirectClick on UserControl



Mario
Nov 13, 2014, 9:13 AM
Hi,

I need to execute a work when I click on Button that is in UserControl loaded dinamically.
But the code returns error....

The code:


Test.aspx



<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Test.aspx.vb" Inherits="B2B.WEB.Test" %>

<%@ Register assembly="Ext.Net" namespace="Ext.Net" tagprefix="ext" %>

<!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>
<ext:ResourceManager runat="server" />

<ext:Button ID="ButtonTestASPX" runat="server" Text="test ASPX" Icon="Accept" OnDirectClick="ButtonTestASPX_Click" />

<ext:Panel ID="PanelControl" runat="server" Width="500" Border="true" />
</body>
</html>



Test.aspx.vb



Public Class Test
Inherits System.Web.UI.Page

Private Sub Test_Load(sender As Object, e As EventArgs) Handles Me.Load
Dim ControlApp As New Ext.Net.UserControlLoader
ControlApp.Path = "Control.ascx"
PanelControl.Items.Add(ControlApp)
PanelControl.UpdateContent()
End Sub

Protected Sub ButtonTestASPX_Click(sender As Object, e As Ext.Net.DirectEventArgs)
Ext.Net.X.Msg.Alert("Message", "Hello ASPX").Show()
End Sub

End Class



Control.ascx



<%@ Control Language="vb" AutoEventWireup="false" CodeBehind="Control.ascx.vb" Inherits="B2B.WEB.Control" %>

<ext:Button ID="ButtonTestASCX" runat="server" Text="test ASCX" Icon="Accept" OnDirectClick="ButtonTestASCX_Click" />



Control.ascx.vb



Public Class Control
Inherits System.Web.UI.UserControl

Protected Sub ButtonTestASCX_Click(sender As Object, e As Ext.Net.DirectEventArgs)
Ext.Net.X.Msg.Alert("Message", "Hello ASCX").Show()
End Sub

End Class



When I run the code, appear two button.
If I click on first button, all OK... and the message will be showed.
If I click on second button... will display an error and the message will not be shown.

Can you help me?

Tnx!

Daniil
Nov 13, 2014, 12:27 PM
Hi @Mario,

Please read this post:
http://forums.ext.net/showthread.php?23980&p=105183&viewfull=1#post105183

Mario
Nov 13, 2014, 1:14 PM
OK, problem resolved!

In Control.ascx file, change the line:



<ext:Button ID="ButtonTestASCX" runat="server" Text="test ASCX" Icon="Accept" OnDirectClick="ButtonTestASCX_Click" />


in...



<ext:Button ID="ButtonTestASCX" runat="server" Text="test ASCX" Icon="Accept" ClientIDMode="Static" OnDirectClick="ButtonTestASCX_Click" />


:)

Daniil
Nov 14, 2014, 9:29 AM
I've just realized (due to your other thread) that you don't create controls on the fly. So, my answer was not correct. There is another problem, I think.

Please remove:

PanelControl.UpdateContent()

It should be called during a DirectEvent only if needed to update the PanelControl's content.

Mario
Nov 14, 2014, 11:20 AM
Tnx Daniil,

It work very good!