Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Professional For advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 7th, 2008, 02:46 AM
Authorized User
 
Join Date: Apr 2006
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to vivekshah Send a message via Yahoo to vivekshah
Default Problem while using User Control

Hello everybody,

I am having a website with Asp.net(VB) in VS2003.

I have created a user control that contains a dropdownlist and I am trying to get the value of the item selected on dropdown's selectedIndexChanged Event.

Below is my code for User control Ctrl.ascx.vb
Code:
'--- CODE FOR USER CONTROL-----------
Imports System
Imports System.Web.UI.WebControls
Imports System.Data
Public Class Ctrl
    Inherits System.Web.UI.UserControl

#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 ddlTest As System.Web.UI.WebControls.DropDownList

    '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

    Public Delegate Sub SelectedIndexChangedHandler(ByVal sender As Object, ByVal args As SelectedIndexChangedEventArgs)
    Public Event myselectedIndexChanged As SelectedIndexChangedHandler

    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
    End Sub

    Private Sub ddlTest_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ddlTest.SelectedIndexChanged

        RaiseEvent myselectedIndexChanged(Me, New SelectedIndexChangedEventArgs(ddlTest.SelectedItem))
    End Sub

    Public Class SelectedIndexChangedEventArgs
        Inherits EventArgs
        Private m_selectedItem As ListItem
        Dim a As Integer

        Public ReadOnly Property SelectedItem() As ListItem
            Get
                Return m_selectedItem
            End Get
        End Property
        Public Sub New(ByVal selectedItem As ListItem)
            m_selectedItem = selectedItem
        End Sub

    End Class

End Class
Below is the code for the Webform2.aspx where I want to get the value of dropdown.

Code:
'----CODE FOR THE ASPX PAGE-----------

Public Class WebForm2
    Inherits System.Web.UI.Page

    Protected myCtrl As Ctrl.SelectedIndexChangedHandler
    'Protected tempCtrl As New Ctrl
    Private WithEvents xyz As New Ctrl
    Protected obj As New Ctrl.SelectedIndexChangedHandler(AddressOf ProcessIndexChangedEvent)
#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub

    '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

    End Sub
    Private Sub ProcessIndexChangedEvent(ByVal Sender As Object, ByVal e As DelegateInVB.Ctrl.SelectedIndexChangedEventArgs) Handles xyz.myselectedIndexChanged
        Response.Write("U Selected: " & e.SelectedItem.Text)
    End Sub

    Public Sub New()
        AddHandler xyz.myselectedIndexChanged, obj
    End Sub
End Class

Problem is that I am not able to get value selected in dropdown on the parent aspx page.

Please can anyone help me out to find what's going wrong here?



Thanks in advance.Your help would be appreciated

Vivek Shah
__________________
Vivek Shah





Similar Threads
Thread Thread Starter Forum Replies Last Post
Much much problem with the User Control! daffodils ASP.NET 1.0 and 1.1 Basics 7 October 20th, 2006 10:46 AM
Dynamic user control problem sandeep General .NET 0 September 26th, 2005 09:42 AM
User Control Problem alyeng2000 ASP.NET 1.0 and 1.1 Basics 4 March 19th, 2004 11:22 PM
Web User Control Problem shmacgregor VS.NET 2002/2003 18 February 22nd, 2004 06:29 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.