Dynamic WebUserControls Button Click event-VBForums
Results 1 to 1 of 1

Thread: Dynamic WebUserControls Button Click event

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2002
    Posts
    77

    Dynamic WebUserControls Button Click event

    I've been googling all day but I still can't get the button click event on
    a dynamic WebUserControl to fire.

    I've tried raising events delegates and everything else I can find.
    The text in the controls seems to persist okay but no button clicks.

    hopefully it's not relevent but I am using a WebApplication under VS2005

    Thanks in advance.

    here is my basic test code for the WebUserControl:

    Code:
    <%@ Control Language="vb" AutoEventWireup="false" CodeBehind="wuc.ascx.vb" Inherits="WebApplication1.wuc" %>
    &nbsp;<asp:TextBox ID="TextBox1" runat="server" Width="216px">zzz</asp:TextBox>
    <asp:Button ID="Button1" runat="server" Text="Button" />
    Code:
    Partial Public Class wuc
        Inherits System.Web.UI.UserControl
    
    
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        End Sub
    
        Public Property txt() As String
            Get
                Return TextBox1.Text
            End Get
            Set(ByVal value As String)
                TextBox1.Text = value
            End Set
        End Property
    
    
        Protected Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            ' breakpoint here is never reached !
        End Sub
    End Class

    here is my basic test code for the default page:

    Code:
    <%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="WebApplication1._Default" %>
    
    <%@ Register Src="wuc.ascx" TagName="wuc" TagPrefix="uc1" %>
    
    <!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>Untitled Page</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:Button ID="ButtonNew" runat="server" Text="Button" Width="144px" />&nbsp;
            <asp:Panel ID="Panel1" runat="server" Height="192px" Width="368px">
            </asp:Panel>
            </div>
        </form>
    </body>
    </html>
    Code:
    Partial Public Class _Default
    
    
        Inherits System.Web.UI.Page
    
        Private Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
            If Page.IsPostBack Then
                Dim WL As List(Of wuc) = Session("wuclist")
    
                Dim count As Int16 = 0
                For Each w As wuc In WL
                    count += 1
                    w.EnableViewState = True
                    w.ID = "wuc" + count.ToString
                    w.txt = "now wuc is: " + w.ID.ToString
                    Panel1.Controls.Add(w)
                Next
    
            Else
                Session("wuclist") = New List(Of wuc)
                Panel1.Controls.Clear()
            End If
    
        End Sub
    
    
        Protected Sub ButtonNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonNew.Click
            Dim WL As List(Of wuc) = Session("wuclist")
            Dim count As Int16 = WL.Count + 1
    
            Dim wuc1 As New wuc
            wuc1 = DirectCast(LoadControl("~/wuc.ascx"), wuc)
            wuc1.ID = "wuc" + count.ToString
            wuc1.txt = "this is Wuc: " + wuc1.ID.ToString
    
            Panel1.Controls.Add(wuc1)
    
            WL.Add(wuc1)
            Session("wuclist") = WL
        End Sub
    
    
    End Class
    Last edited by grahamxyz; Jan 27th, 2012 at 04:14 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.