|
 |
aspx thread: Re: Dynamically created controls which can respond to client events?
Message #1 by "dHABUD" <dhabud@h...> on Tue, 8 Oct 2002 07:25:02
|
|
Hi
I am adding LinkButton to my panel in the same way as you suggested. But I
am adding this Link button in one of my Sub ROUTINEs instead of SUB
Page_Load()
I am not able to set AddHandler for this Link Button.
Also If i create LinkButton in the form iteself ratehr than
programatically, it does access the btnLink_Click SUB.
The code looks as follows
Function AddLinkButton()
Dim lnkButton as New LinkButton()
lnkButton.Text= "Click Here"
AddHandler lnkButton.Click, AddressOf btnLink_Click
panel1.Controls.Add(lnkButton)
end function
Sub btnLink_Click(obj as object, e as EventArgs)
Response.Write("Clicked Link Button")
End Sub
Any Suggestion are greatly appreciated.
Thanks In Advance
Dhabud
>
> Hi
> Please go through attach code . This code will generate
linkbutton,
> command button control dynamically , also handles click event of that
> control.
> Let me know if you need further elobration .Run this code & see the
> o/p .
>
> Regards,
> Neeta
>
> 'This program adds the server control dynamically and handles
> 'the events of the added control
> Public Class DynamicControl
> Inherits System.Web.UI.Page
> Protected WithEvents Panel1 As System.Web.UI.WebControls.Panel
> Protected WithEvents Button1 As System.Web.UI.WebControls.Button
> Protected WithEvents Label1 As System.Web.UI.WebControls.Label
> Protected WithEvents Form1 As System.Web.UI.HtmlControls.HtmlForm
>
> #Region " Web Form Designer Generated Code "
>
> 'This call is required by the Web Form Designer.
> <System.Diagnostics.DebuggerStepThrough()> Private Sub
> InitializeComponent()
>
> End Sub
>
> 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
> Dim l As New LinkButton()
> Dim cn As System.Web.UI.Control
> l.Text = "hello"
> AddHandler l.Click, AddressOf show
> Label1.Controls.Add(l)
> If IsPostBack Then
> If Request.Form("__EVENTTARGET") = "btn" Then
> Check()
> End If
> End If
>
> End Sub
>
> Public Sub show(ByVal s As Object, ByVal e As EventArgs)
> Response.Write("Dynamically Added Link Button is Clicked")
> End Sub
>
> Public Sub Check()
> CreateTable()
> End Sub
> Public Sub clk(ByVal s As Object, ByVal e As EventArgs)
> Response.Write("Dynamically Added Button is Clicked")
> End Sub
>
> Public Sub clkBtn(ByVal s As Object, ByVal e As EventArgs)
> 'CreateTable()
> Response.Write("Dynamically Created Button in Table is Clicked")
> End Sub
>
> Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles Button1.Click
> CreateTable()
> End Sub
>
> Private Sub CreateTable()
> Dim tbl As New System.Web.UI.WebControls.Table()
> Dim rw As New System.Web.UI.WebControls.TableRow()
> Dim cl As New System.Web.UI.WebControls.TableCell()
> Dim btnCell As New System.Web.UI.HtmlControls.HtmlButton()
> btnCell.InnerText = "Btn In Table"
> btnCell.ID = "btn"
> AddHandler btnCell.ServerClick, New EventHandler(AddressOf
clkBtn)
> cl.Controls.Add(btnCell)
> rw.Controls.Add(cl)
> tbl.Controls.Add(rw)
> tbl.ID = "tbl"
> Form1.Controls.AddAt(4, tbl)
>
> End Sub
> End Class
>
>
Message #2 by Thomas Fuller <TFuller@g...> on Tue, 8 Oct 2002 09:20:10 -0400
|
|
I ran into this same issue a while back when I was trying to dynamically
generate a whole form based on the database layout from a tabstrip control.
The answer given to me was you were unable to add event handlers after the
page_load due to the page execution model. It was described as a
bug/limitation of the framework. If anyone has a better explanation I'd
love to hear it because I refuse to believe .net can't do this (or anything
for that matter).
Tom Fuller
-----Original Message-----
From: dHABUD [mailto:dhabud@h...]
Sent: Tuesday, October 08, 2002 3:25 AM
To: ASP+
Subject: [aspx] Re: Dynamically created controls which can respond to client
events?
Hi
I am adding LinkButton to my panel in the same way as you suggested. But I
am adding this Link button in one of my Sub ROUTINEs instead of SUB
Page_Load()
I am not able to set AddHandler for this Link Button.
Also If i create LinkButton in the form iteself ratehr than
programatically, it does access the btnLink_Click SUB.
The code looks as follows
Function AddLinkButton()
Dim lnkButton as New LinkButton()
lnkButton.Text= "Click Here"
AddHandler lnkButton.Click, AddressOf btnLink_Click
panel1.Controls.Add(lnkButton)
end function
Sub btnLink_Click(obj as object, e as EventArgs)
Response.Write("Clicked Link Button")
End Sub
Any Suggestion are greatly appreciated.
Thanks In Advance
Dhabud
>
> Hi
> Please go through attach code . This code will generate
linkbutton,
> command button control dynamically , also handles click event of that
> control.
> Let me know if you need further elobration .Run this code & see the
> o/p .
>
> Regards,
> Neeta
>
> 'This program adds the server control dynamically and handles
> 'the events of the added control
> Public Class DynamicControl
> Inherits System.Web.UI.Page
> Protected WithEvents Panel1 As System.Web.UI.WebControls.Panel
> Protected WithEvents Button1 As System.Web.UI.WebControls.Button
> Protected WithEvents Label1 As System.Web.UI.WebControls.Label
> Protected WithEvents Form1 As System.Web.UI.HtmlControls.HtmlForm
>
> #Region " Web Form Designer Generated Code "
>
> 'This call is required by the Web Form Designer.
> <System.Diagnostics.DebuggerStepThrough()> Private Sub
> InitializeComponent()
>
> End Sub
>
> 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
> Dim l As New LinkButton()
> Dim cn As System.Web.UI.Control
> l.Text = "hello"
> AddHandler l.Click, AddressOf show
> Label1.Controls.Add(l)
> If IsPostBack Then
> If Request.Form("__EVENTTARGET") = "btn" Then
> Check()
> End If
> End If
>
> End Sub
>
> Public Sub show(ByVal s As Object, ByVal e As EventArgs)
> Response.Write("Dynamically Added Link Button is Clicked")
> End Sub
>
> Public Sub Check()
> CreateTable()
> End Sub
> Public Sub clk(ByVal s As Object, ByVal e As EventArgs)
> Response.Write("Dynamically Added Button is Clicked")
> End Sub
>
> Public Sub clkBtn(ByVal s As Object, ByVal e As EventArgs)
> 'CreateTable()
> Response.Write("Dynamically Created Button in Table is Clicked")
> End Sub
>
> Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles Button1.Click
> CreateTable()
> End Sub
>
> Private Sub CreateTable()
> Dim tbl As New System.Web.UI.WebControls.Table()
> Dim rw As New System.Web.UI.WebControls.TableRow()
> Dim cl As New System.Web.UI.WebControls.TableCell()
> Dim btnCell As New System.Web.UI.HtmlControls.HtmlButton()
> btnCell.InnerText = "Btn In Table"
> btnCell.ID = "btn"
> AddHandler btnCell.ServerClick, New EventHandler(AddressOf
clkBtn)
> cl.Controls.Add(btnCell)
> rw.Controls.Add(cl)
> tbl.Controls.Add(rw)
> tbl.ID = "tbl"
> Form1.Controls.AddAt(4, tbl)
>
> End Sub
> End Class
>
>
---
ASP.NET 1.0 Namespace Reference with C#
http://www.wrox.com/acon11.asp?ISBN=1861007442
ASP.NET 1.0 Namespace Reference with VB.NET
http://www.wrox.com/acon11.asp?ISBN=1861007450
These books are a complete reference to the ASP.NET namespaces
for developers who are already familiar with using ASP.NET.
There is no trivial introductory material or useless .NET
hype and the presentation of the namespaces, in an easy-to use
alphabetical order ensures a user-friendly reference format.
We provide in-depth coverage of all the major ASP.NET classes,
giving you those real-world tips that the documentation doesn't
offer, and demonstrating complex techniques with simple
examples.
---
|
|
 |