Adding Event Handler in Vb.net

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ria12
    New Member
    • Feb 2009
    • 26

    Adding Event Handler in Vb.net

    Hi...Guys

    I have a created a Modal popup as a usercontrol .it also have a button .I want to handle button event of usercontrol on parent page by registering it on parent page.but it does not work properly...plz help me....
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    This wont work.

    The button click event belongs to the user control, and so it has to be handled in the user control.

    You could raise an event in your user control, which could be handled in your parent page, that indicates the button was clicked.

    Comment

    • Ria12
      New Member
      • Feb 2009
      • 26

      #3
      anybody tell me how....i handle button event of user control on parentpage....
      plz help me urgently....

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        I told you.

        In the button click event in the user control raise a new event.

        If you don't know how to raise an event, check out this article on how to use events in .NET.

        Comment

        • Ria12
          New Member
          • Feb 2009
          • 26

          #5
          I Read ur Link . i 'm new to vb.net just using from last 2 months.I donot understand where i have to use.I send u my code..
          My UserControl Page Name User.ascx
          Code:
          <%@ Control Language="VB" AutoEventWireup="false" CodeFile="UserctrlPopl.ascx.vb" Inherits="UserctrlPopl" %>
          <style type ="text/css">
             
          	.modalPopup {
          	background-color:#ffffdd;
          	border-width:3px;
          	border-style:solid;
          	border-color:Gray;
          	padding:3px;
          	width:250px;
          }
            
          </style>
              <table class="modalPopup" style="z-index: 100; left: 20px; position: absolute; top: 17px; height: 106px">
                <tr>
                <td style="cursor: move;background-color:#DDDDDD;border:solid 1px Gray;color:Black; width: 359px; height: 99px;">
                           <br />      Your Request is under processing....<br />
                                        </td>
                    </tr>
                 <tr>
                    <td >
                        <asp:Button ID="AddButton" runat ="server"  Text="Next" />
                      </td>
                 </tr>        
            </table>

          My ParentPage AdCreation.aspx
          Code:
          <%@ Register Src="~/UserctrlPopl.ascx" TagName ="PopUp5" TagPrefix="bcu"   %>
          
          
           <asp:Button ID="AddButton" runat="server" Text="Next" style="z-index: 114; left: 295px; position: absolute; top: 237px" CausesValidation="false" BackColor="ActiveBorder" />                            
                     
                                 <ajaxToolkit:ModalPopupExtender ID="UserCtrlextender" runat="server" 
                                                    TargetControlID="AddButton"
                                                    PopupControlID="PanelCtrl" 
                                                    BackgroundCssClass="modalBackground" 
                                                    CancelControlID="CancelButton"   
                                                    DropShadow="true"
                                                     />       
          
                                                                                        
                              <asp:Panel ID ="PanelCtrl" runat="server">
                                <div>
                               <bcu:PopUp5 ID="user8" runat="server" />   
                                </div>
                              </asp:Panel>
          I donot understand what i have to write in my user.ascx.vb page and AdCreation.aspx .vb page

          i have AddButton on my both pages AddButton click of user.ascx page redirected to another page,That is what i actually want to handle on my AdCreation.aspx page .AdCreation.asp x page button AddButton click open a model popup as usercontrol.
          Plz Help me......
          Last edited by Frinavale; Apr 6 '09, 01:34 PM. Reason: Added [code] tags. Please post code in [code] [/code] tags.

          Comment

          • Frinavale
            Recognized Expert Expert
            • Oct 2006
            • 9749

            #6
            Change to Design view.
            Double click on the Add button.

            This will bring you to the VB.NET code and will automatically create a method that will handle the button click event. It will look something like the following:

            Code:
            Partial Public Class UserctrlPopl
                Inherits System.Web.UI.UserControl
            
                Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            
                End Sub
            
                Private Sub AddButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles AddButton.Click
            
                End Sub
            
            End Class
            Once you're viewing the VB.NET code, declare a new event (maybe call it "AddClick" or something).


            Code:
            Partial Public Class UserctrlPopl
                Inherits System.Web.UI.UserControl
            
            
                Public Event AddClick As EventHandler
            
            
            
                Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            
                End Sub
            
                Private Sub AddButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles AddButton.Click
            
                End Sub
            
            End Class
            In the method that handles the Button Click event you will raise the Add Click event:

            Code:
            Private Sub AddButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles AddButton.Click
              
                RaiseEvent AddClick(Me, New EventArgs)
            End Sub


            Now in your Parent page (your AdCreation page) you will have to handle the AddClick event (which you created) for your user control:

            Code:
            Private Sub PopUp5_AddClick(ByVal sender As Object, ByVal e As System.EventArgs) Handlese PopUp5.AddClick
            
                'Do Stuff Here
            
            End Sub

            Comment

            • Ria12
              New Member
              • Feb 2009
              • 26

              #7
              thanks Frinavale.....c ode help me....my event works well as I want...

              Comment

              Working...