S
schleichv
Hello,
I am attempting to get the ServerClick event to fire on a dynamically
generated HtmlInputImage and having no luck at all. I've looked over
many items on the forums but none seem to cover what seems to be
happening to me.
Below is a small test I have put together to demonstrate the issue.
The form has an HtmlInputImage on it that has it's ServerClick event
wired in the code. Another HtmlInputImage is generated in the code and
also has it's ServerClick event wired.
The control that has been defined in the HTML works and the one
generated in code does not.
Thanks in advance for any help.
<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="TestPage.aspx.vb" Inherits="EngAppTracking.TestPage"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>TestPage</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<input id="inImage1" type="image" src="xxx.jpg" runat="server" >
</form>
</body>
</HTML>
Public Class TestPage
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
End Sub
Protected WithEvents inImage1 As
System.Web.UI.HtmlControls.HtmlInputImage
Protected WithEvents inImage2 As
System.Web.UI.HtmlControls.HtmlInputImage
'NOTE: The following placeholder declaration is required by the Web
Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
'context.Session(SessionVariables.IsAdminModeOn) = True
End Sub
Protected Sub HandleImputImageControls()
AddHandler Me.inImage1.ServerClick, AddressOf
Me.inImage1_ServerClick
inImage2 = New HtmlInputImage
inImage2.ID = "inImage2"
inImage2.Src = "xxx.jpg"
inImage2.Attributes.Add("runat", "server")
AddHandler inImage2.ServerClick, AddressOf
Me.inImage2_ServerClick
End Sub
Private Sub inImage1_ServerClick(ByVal sender As System.Object,
ByVal e As System.Web.UI.ImageClickEventArgs)
Response.Write("inImage1 clicked")
End Sub
Private Sub inImage2_ServerClick(ByVal sender As System.Object,
ByVal e As System.Web.UI.ImageClickEventArgs)
Response.Write("inImage2 clicked")
End Sub
Protected Overrides Sub OnInit(ByVal e As System.EventArgs)
HandleImputImageControls()
End Sub
Protected Overrides Sub Render(ByVal writer As
System.Web.UI.HtmlTextWriter)
Dim MyForm As HtmlForm
MyForm = Me.FindControl("Form1")
MyForm.Controls.Add(inImage2)
MyForm.RenderControl(writer)
End Sub
End Class
I am attempting to get the ServerClick event to fire on a dynamically
generated HtmlInputImage and having no luck at all. I've looked over
many items on the forums but none seem to cover what seems to be
happening to me.
Below is a small test I have put together to demonstrate the issue.
The form has an HtmlInputImage on it that has it's ServerClick event
wired in the code. Another HtmlInputImage is generated in the code and
also has it's ServerClick event wired.
The control that has been defined in the HTML works and the one
generated in code does not.
Thanks in advance for any help.
<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="TestPage.aspx.vb" Inherits="EngAppTracking.TestPage"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>TestPage</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<input id="inImage1" type="image" src="xxx.jpg" runat="server" >
</form>
</body>
</HTML>
Public Class TestPage
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
End Sub
Protected WithEvents inImage1 As
System.Web.UI.HtmlControls.HtmlInputImage
Protected WithEvents inImage2 As
System.Web.UI.HtmlControls.HtmlInputImage
'NOTE: The following placeholder declaration is required by the Web
Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
'context.Session(SessionVariables.IsAdminModeOn) = True
End Sub
Protected Sub HandleImputImageControls()
AddHandler Me.inImage1.ServerClick, AddressOf
Me.inImage1_ServerClick
inImage2 = New HtmlInputImage
inImage2.ID = "inImage2"
inImage2.Src = "xxx.jpg"
inImage2.Attributes.Add("runat", "server")
AddHandler inImage2.ServerClick, AddressOf
Me.inImage2_ServerClick
End Sub
Private Sub inImage1_ServerClick(ByVal sender As System.Object,
ByVal e As System.Web.UI.ImageClickEventArgs)
Response.Write("inImage1 clicked")
End Sub
Private Sub inImage2_ServerClick(ByVal sender As System.Object,
ByVal e As System.Web.UI.ImageClickEventArgs)
Response.Write("inImage2 clicked")
End Sub
Protected Overrides Sub OnInit(ByVal e As System.EventArgs)
HandleImputImageControls()
End Sub
Protected Overrides Sub Render(ByVal writer As
System.Web.UI.HtmlTextWriter)
Dim MyForm As HtmlForm
MyForm = Me.FindControl("Form1")
MyForm.Controls.Add(inImage2)
MyForm.RenderControl(writer)
End Sub
End Class