How to clear a user control's controls

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ria12
    New Member
    • Feb 2009
    • 26

    How to clear a user control's controls

    hi,
    I have a user control registered on my parent page.parent page have a link of Add new employee when click on a link user control opened after save click it save all the information,whe n againly click on link it show previous information that was saved ..plz help me how to clear user control's all control
  • PRR
    Recognized Expert Contributor
    • Dec 2007
    • 750

    #2
    Use Page.Findcontrol to get a reference to usercontrol and then use usercontrol .findcontrol to get access to usercontrol controls like textbox....
    Another way would be define public method/properties in user control and clear the text...

    Comment

    • maliksleo
      New Member
      • Feb 2009
      • 115

      #3
      you can do it by just redirecting to the same page. It will refresh the page and reload it from the begining and all the previous data will not show again.
      If you dont want to redirect your page then you will have to clear all the controls on save button's click event.
      Or else show your code for better understanding and suggestion for a different solution.

      maliksleo

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        Originally posted by Ria12
        hi,
        I have a user control registered on my parent page.parent page have a link of Add new employee when click on a link user control opened after save click it save all the information,whe n againly click on link it show previous information that was saved ..plz help me how to clear user control's all control
        Implement a public method called "ResetEmplo yee" or "ClearEmployeeI nfo" something in your user control. This method should "clear"/reset any information.

        For example:
        Code:
        Public Sub ClearEmployeeInfo()
          txt_firstName.Text = ""
          txt_lastName.Text = ""
          txt_employeeNumber.Text = ""
          txt_phoneNumber.Text = ""
          txt_address.Text = ""
        //.......
        End Sub
        Since this method is Public you can call it from your main page code (say in your save button click):

        Code:
        Private Sub btn_Save_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn_Save.Click
        //....save data
           myUserControlInstance.ClearEmployeeInfo()
        
        End Sub

        Comment

        Working...