473,396 Members | 2,108 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Adding Event Handler in Vb.net

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
6 10599
Frinavale
9,735 Expert Mod 8TB
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
Ria12
26
anybody tell me how....i handle button event of user control on parentpage....
plz help me urgently....
Apr 3 '09 #3
Frinavale
9,735 Expert Mod 8TB
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
Ria12
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
9,735 Expert Mod 8TB
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
Ria12
26
thanks Frinavale.....code help me....my event works well as I want...
Apr 7 '09 #7

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

Similar topics

2
by: RobG | last post by:
I am trying to dynamically add an onclick to an element, however I just can't get the syntax right. consider the following function: function doClick (evt,x) { // do things with evt and x } ...
2
by: laredotornado | last post by:
Hello, I am looking for a cross-browser way (Firefox 1+, IE 5.5+) to have my Javascript function execute from the BODY's "onload" method, but if there is already an onload method defined, I would...
3
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that...
2
by: Tim Marsden | last post by:
Hi, This is what I am doing, please comment if this is the correct way. I need to add controls to a form dynamically. Within the Page_Load event (is not Postback) I run a routine to create the...
2
by: Shiju Poyilil | last post by:
Hi ! I have a requirement wherein i am binding a datalist which contains a label (Caption for the field) and some literal hidden fields and a dropdown list. When I am binding to the datalist.....
4
by: PK9 | last post by:
I have a button at the top of my page that I have an onClick event handler for which makes some new controls (at the bottom of my page) visible. When the user clicks the button I make the new...
1
by: seanmayhew | last post by:
I have a form page that that while editing saves the data to an xml doc before submitting to db. On each page unload it saves the xmldoc as the user can add multiple items to the company like...
6
by: Just Me | last post by:
I need to create a library sub that adds event handlers to a control. Public Shared Sub AddEvent(ByVal qq As Control, By?? ControlMouseMove As ??) So I need to pass the address of the handler or...
5
by: J | last post by:
I am having problems dynamically adding more than one event handler to an input. I have tried the Javascript included at the bottom. The lines inp.attachEvent('onkeyup',...
1
by: The Eclectic Electric | last post by:
I'd be very grateful if anyone could help me with this. From my limited knowledge of Javascript I don't think it is possible, but I'll punt anyway. I downloaded and very slightly adapted this...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.