web user controls problem
Hi all,
I have a problem here. I have created two web user controls on a aspx page and it's working fine. The problem is that each of the Web User Control has an save button and it causes the page to have two buttons on my aspx page. I would like to remove a button from a user control and put the button behaviour on to another user control so I would only have one save button on my aspx page.
From UserControl1.ascx
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
Call updateToDatabase() ' save some data
'if dates are added, assign behaviour to the button
If Session("added") = "true" Then '
Dim cal As Calendar1
cal = New Calendar1
AddHandler btnSave.Click, AddressOf cal.btnSave_Click2 ' Click2 behaviour is from Calendar Object
End If
End Sub
Does anyone know is there a way to tackle this?
Please help?
kero
[1091 byte] By [
kero] at [2007-11-11 6:38:46]

# 1 Re: web user controls problem
Why not add a ShowSaveButton property to one (or both) of the controls? If the property is True, show the Save button; if not, hide it.
# 2 Re: web user controls problem
Yes, I could but I still need the calendar controls behaviour in my UserControl1 in order to save all the data on the form. My form has seperated into two sections with two buttons at the moment. I am having trouble to assign the button behaviour. The error message says object is not reference to something... I am a bit confused how to work around with this now...
please help
kero
kero at 2007-11-11 23:15:17 >

# 3 Re: web user controls problem
I have Session("added") on both Web User Controls. The error message kept on saying I haven't got a object reference for the Session("added") on calendar control. I am not sure am I doing something wrong. I have created an instance of an calendar object and then use its save method to store the dates, but I can't make it to work.
Please help Phil
Thanks
kero
kero at 2007-11-11 23:16:22 >

# 4 Re: web user controls problem
Hi all,
I wonder is it possible to share a button behaviour between two web user controls?
eg.
web user control A has a save button
web user control B has a save button too..
I want to assign control B's save button to control A so I could have one save button that can save two things at once.
I have tried to call web user control B's save method from web user control A, but nothing work.
System.Web.UI.UserControl.CalendarB.saveMethod()
system.Web.UI.Control.CalendarB.saveMehtod()
Dim cal As CalendarB
cal = new CalendarB
cal.saveMethod ' error object is not referenced
CalendarB.saveMethod
Please help
kero
kero at 2007-11-11 23:17:16 >

# 5 Re: web user controls problem
The whole point of creating a user control is to create a reusable component. If user control A knows about/relies on user control B, then it's no longer an independent component and will be much more difficult to reuse.
If you want a Save button to trigger methods of multiple controls, the button should raise an event on the Page. The Page event handler may then call whatever methods you wish to execute. For more information, see http://codebetter.com/blogs/brendan.tompkins/archive/2004/10/06/27795.aspx