By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,996 Members | 884 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,996 IT Pros & Developers. It's quick & easy.

Adding Event Handler in Vb.net

P: 26
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....
Apr 1 '09 #1
Share this Question
Share on Google+
6 Replies


Frinavale
Expert Mod 5K+
P: 9,731
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.
Apr 1 '09 #2

P: 26
anybody tell me how....i handle button event of user control on parentpage....
plz help me urgently....
Apr 3 '09 #3

Frinavale
Expert Mod 5K+
P: 9,731
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.
Apr 3 '09 #4

P: 26
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
Expand|Select|Wrap|Line Numbers
  1. <%@ Control Language="VB" AutoEventWireup="false" CodeFile="UserctrlPopl.ascx.vb" Inherits="UserctrlPopl" %>
  2. <style type ="text/css">
  3.  
  4.     .modalPopup {
  5.     background-color:#ffffdd;
  6.     border-width:3px;
  7.     border-style:solid;
  8.     border-color:Gray;
  9.     padding:3px;
  10.     width:250px;
  11. }
  12.  
  13. </style>
  14.     <table class="modalPopup" style="z-index: 100; left: 20px; position: absolute; top: 17px; height: 106px">
  15.       <tr>
  16.       <td style="cursor: move;background-color:#DDDDDD;border:solid 1px Gray;color:Black; width: 359px; height: 99px;">
  17.                  <br />      Your Request is under processing....<br />
  18.                               </td>
  19.           </tr>
  20.        <tr>
  21.           <td >
  22.               <asp:Button ID="AddButton" runat ="server"  Text="Next" />
  23.             </td>
  24.        </tr>        
  25.   </table> 

My ParentPage AdCreation.aspx
Expand|Select|Wrap|Line Numbers
  1. <%@ Register Src="~/UserctrlPopl.ascx" TagName ="PopUp5" TagPrefix="bcu"   %>
  2.  
  3.  
  4.  <asp:Button ID="AddButton" runat="server" Text="Next" style="z-index: 114; left: 295px; position: absolute; top: 237px" CausesValidation="false" BackColor="ActiveBorder" />                            
  5.  
  6.                        <ajaxToolkit:ModalPopupExtender ID="UserCtrlextender" runat="server" 
  7.                                           TargetControlID="AddButton"
  8.                                           PopupControlID="PanelCtrl" 
  9.                                           BackgroundCssClass="modalBackground" 
  10.                                           CancelControlID="CancelButton"   
  11.                                           DropShadow="true"
  12.                                            />       
  13.  
  14.  
  15.                     <asp:Panel ID ="PanelCtrl" runat="server">
  16.                       <div>
  17.                      <bcu:PopUp5 ID="user8" runat="server" />   
  18.                       </div>
  19.                     </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.aspx page button AddButton click open a model popup as usercontrol.
Plz Help me......
Apr 6 '09 #5

Frinavale
Expert Mod 5K+
P: 9,731
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:

Expand|Select|Wrap|Line Numbers
  1. Partial Public Class UserctrlPopl
  2.     Inherits System.Web.UI.UserControl
  3.  
  4.     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  5.  
  6.     End Sub
  7.  
  8.     Private Sub AddButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles AddButton.Click
  9.  
  10.     End Sub
  11.  
  12. End Class
  13.  
Once you're viewing the VB.NET code, declare a new event (maybe call it "AddClick" or something).


Expand|Select|Wrap|Line Numbers
  1. Partial Public Class UserctrlPopl
  2.     Inherits System.Web.UI.UserControl
  3.  
  4.  
  5.     Public Event AddClick As EventHandler
  6.  
  7.  
  8.  
  9.     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  10.  
  11.     End Sub
  12.  
  13.     Private Sub AddButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles AddButton.Click
  14.  
  15.     End Sub
  16.  
  17. End Class
  18.  
In the method that handles the Button Click event you will raise the Add Click event:

Expand|Select|Wrap|Line Numbers
  1. Private Sub AddButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles AddButton.Click
  2.  
  3.     RaiseEvent AddClick(Me, New EventArgs)
  4. 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:

Expand|Select|Wrap|Line Numbers
  1. Private Sub PopUp5_AddClick(ByVal sender As Object, ByVal e As System.EventArgs) Handlese PopUp5.AddClick
  2.  
  3.     'Do Stuff Here
  4.  
  5. End Sub
Apr 6 '09 #6

P: 26
thanks Frinavale.....code help me....my event works well as I want...
Apr 7 '09 #7

Post your reply

Sign in to post your reply or Sign up for a free account.