473,498 Members | 523 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Calling methods inside a user control from the container control

Hi,

I have an aspx page page with some existing controls code etc. This page has
an update button which updates a SQL Db based on any user changes. I need to
add a new section to this page and a few other pages. I think that it's best
to create a user control for this purpose. This user control will contain a
number of webcontrols e.g textbox, dropdown etc When the user clicks update
on the main page I need to update the DB as before for the original controls
plus the new ones from the user control.

What is the best way to do this? I thought that the user control should have
its own methods to take care of the updates but how should the main page call
these methods or is there a better way to do this?
Nov 18 '05 #1
1 1898
The best way, in my opinion, is to have the page raise an event, which the
user controls are hooked into.

Basically, your page defines an event:
Public Event Save As EventHandler

on the click event of the page, you raise the event:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
RaiseEvent Save(Me, e)
End Sub

in the user control(s) you hook into the event:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
AddHandler CType(Page, TYPEOFPAGEHERE).Save, AddressOf OnSave
'TYPEOFPAGEHERE is going to be like WebForm1 or something
End Sub

and then you have your control's save function:

Private Sub OnSave(ByVal source As Object, ByVal e As EventArgs)
'do your magic here
End Sub

Karl

"Neil" <Ne**@discussions.microsoft.com> wrote in message
news:1E**********************************@microsof t.com...
Hi,

I have an aspx page page with some existing controls code etc. This page has an update button which updates a SQL Db based on any user changes. I need to add a new section to this page and a few other pages. I think that it's best to create a user control for this purpose. This user control will contain a number of webcontrols e.g textbox, dropdown etc When the user clicks update on the main page I need to update the DB as before for the original controls plus the new ones from the user control.

What is the best way to do this? I thought that the user control should have its own methods to take care of the updates but how should the main page call these methods or is there a better way to do this?

Nov 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
1347
by: Doug Rosser | last post by:
I'm writing a fairly complicated test framework and keeping configuration data inside ini files that are parsed at runtime by the ConfigParser module. For example, there would be a section...
0
965
by: Andy Eshtry | last post by:
Hello Dear Professionals: Based on this document: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbtskcreatingwebservercontroltemplatesdynamically.asp or this...
2
4205
by: Andrea Gavana | last post by:
Hello NG, this may seem a stupid (or even impossible) question, but my knowlegde of Python is quite limited. I have basically a simple graphical user interface that contains a Panel, another...
0
1418
by: Oleg G. | last post by:
Hi there! I have datagrid with template column and I am using the same user control for display (in ItemTemplate) and collect (in EditItemTemplate) information. The user control is a number of...
1
2691
by: Danny Ni | last post by:
Hi, I have a web form A that contains an user control B, which contains an user control C. Inside user control C, can I call methods in user control B and web form A? If yes, How? The mthods...
5
3033
by: djscratchnsniffing | last post by:
i know you can access an ascx's properties/methods from an aspx file. Let's say you have an aspx file with two code-behind files(ascx files). Can you access one of the ascx file's...
8
3001
by: fernandezr | last post by:
I would like to use a user control as a template inside a repeater. Some of the fields in the control should be hidden depending on whether or not there is data. I'm still a ASP .Net newbie so the...
8
1976
by: Stinky Pete | last post by:
OK, I am thoroughly confused. All I am trying to do is fill in a Status field on my form with the condtions below, with all my theory being based on what I have read in various newsgropups. The...
2
2303
by: ccbalapatel | last post by:
Hi, We have recently converted our code to ASP.NET 2.0. We have an user control that is embedded inside the page. The user control has a link button and the event handler for the link button is...
0
7124
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6998
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
7163
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
5460
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,...
1
4904
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4586
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3090
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
651
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.