DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 6 of 6

Thread: web user controls problem

  1. #1
    Join Date
    Feb 2005
    Posts
    91

    Question 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

    Code:
    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
    Last edited by kero; 08-17-2005 at 10:45 AM.

  2. #2
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    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.
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  3. #3
    Join Date
    Feb 2005
    Posts
    91
    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
    Last edited by kero; 08-18-2005 at 03:45 AM.

  4. #4
    Join Date
    Feb 2005
    Posts
    91
    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

  5. #5
    Join Date
    Feb 2005
    Posts
    91
    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.

    Code:
    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
    Last edited by kero; 08-18-2005 at 06:15 AM.

  6. #6
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    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..../06/27795.aspx
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

Similar Threads

  1. Replies: 0
    Last Post: 08-16-2005, 10:36 AM
  2. Replies: 0
    Last Post: 03-21-2003, 05:00 PM
  3. Disappearing controls in web forms designer
    By Yair Alan Griver [MS] in forum dotnet.announcements
    Replies: 1
    Last Post: 09-11-2002, 11:00 PM
  4. Search Label Controls in Web Form
    By Kee Peck in forum ASP.NET
    Replies: 2
    Last Post: 05-23-2002, 12:35 PM
  5. pass a form to a web user control (pagelet)
    By Annie Wang in forum ASP.NET
    Replies: 0
    Last Post: 05-24-2001, 04:07 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center