Results 1 to 7 of 7

Thread: Problem on inheriting from web form

  1. #1

    Thread Starter
    Hyperactive Member Utpal's Avatar
    Join Date
    Feb 2002
    Location
    Mumbai, India
    Posts
    393

    Problem on inheriting from web form

    Hi everybody,

    I have made a web form class which I want to use as a base class for all data entry web forms. Following is the structure of the web form:

    VB Code:
    1. Public Class WFrmEnt
    2.     Inherits System.Web.UI.Page
    3.     Protected WithEvents nLast As System.Web.UI.WebControls.ImageButton
    4.     Protected WithEvents nNext As System.Web.UI.WebControls.ImageButton
    5.     Protected WithEvents nPrev As System.Web.UI.WebControls.ImageButton
    6.     Protected WithEvents nCancel As System.Web.UI.WebControls.Button
    7.     Protected WithEvents nSave As System.Web.UI.WebControls.Button
    8.     Protected WithEvents nMessage As System.Web.UI.WebControls.Label
    9.     Protected WithEvents nDelete As System.Web.UI.WebControls.Button
    10.     Protected WithEvents nModify As System.Web.UI.WebControls.Button
    11.     Protected WithEvents nAdd As System.Web.UI.WebControls.Button
    12.     Protected WithEvents nPrint As System.Web.UI.WebControls.Button
    13.     Protected WithEvents nFilter As System.Web.UI.WebControls.Button
    14.     Protected WithEvents nFirst As System.Web.UI.WebControls.ImageButton
    15.     Protected WithEvents nRemoveFilter As System.Web.UI.WebControls.Button
    16.  
    17.     Private Sub nFirst_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles
    18.  
    19. nFirst.Click
    20.         Navigate(CNavAction.First)
    21.     End Sub
    22.  
    23.     Private Sub nPrev_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles nPrev.Click
    24.         Navigate(CNavAction.Prev)
    25.     End Sub
    26.  
    27.     Private Sub nNext_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles nNext.Click
    28.         Navigate(CNavAction.Next)
    29.     End Sub
    30.  
    31.     Private Sub nLast_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles nLast.Click
    32.         Navigate(CNavAction.Last)
    33.     End Sub
    34.  
    35.     Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
    36.         MyBase.Render(writer)
    37.     End Sub
    38.  
    39. End Class

    For making a data entry web form, I first add a new web form and place all the required controls on it including nAdd, nModify, nDelete, nFirst, nNext, nPrev, etc. After that, in the code behind page, I change the clause "Inherits System.Web.UI.Page" to "Inherits WFrmEnt". Everything works fine.
    But my problem is that when I go to the designer screen of the web form, it inserts the declarations for the variables of the controls that are inherited from the base web form. It inserts the following code:

    VB Code:
    1. Protected WithEvents nLast As System.Web.UI.WebControls.ImageButton
    2.     Protected WithEvents nNext As System.Web.UI.WebControls.ImageButton
    3.     Protected WithEvents nPrev As System.Web.UI.WebControls.ImageButton
    4.     Protected WithEvents nCancel As System.Web.UI.WebControls.Button
    5.     Protected WithEvents nSave As System.Web.UI.WebControls.Button
    6.     Protected WithEvents nMessage As System.Web.UI.WebControls.Label
    7.     Protected WithEvents nDelete As System.Web.UI.WebControls.Button
    8.     Protected WithEvents nModify As System.Web.UI.WebControls.Button
    9.     Protected WithEvents nAdd As System.Web.UI.WebControls.Button
    10.     Protected WithEvents nPrint As System.Web.UI.WebControls.Button
    11.     Protected WithEvents nFilter As System.Web.UI.WebControls.Button
    12.     Protected WithEvents nFirst As System.Web.UI.WebControls.ImageButton
    13.     Protected WithEvents nRemoveFilter As System.Web.UI.WebControls.Button

    However, this is not desirable because these declarations are already present in the base web form class. Is there a way to avoid this automatic insertion of undesired code?
    It is easy when you know it.

  2. #2

    Thread Starter
    Hyperactive Member Utpal's Avatar
    Join Date
    Feb 2002
    Location
    Mumbai, India
    Posts
    393

    Re: Problem on inheriting from web form

    Am I using the right technique of programming?
    It is easy when you know it.

  3. #3

    Thread Starter
    Hyperactive Member Utpal's Avatar
    Join Date
    Feb 2002
    Location
    Mumbai, India
    Posts
    393

    Re: Problem on inheriting from web form

    Does anybody inherit from web forms, or am I the only one doing it? Please somebody answer!
    It is easy when you know it.

  4. #4
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704

    Re: Problem on inheriting from web form

    There is no way to avoid it other than DO NOT ENTER DESIGN MODE. I exclusively use the HTML designer tab - and rarely if ever hit the Designer.

  5. #5
    Addicted Member rdove's Avatar
    Join Date
    Dec 2002
    Location
    Indianapolis
    Posts
    251

    Re: Problem on inheriting from web form

    In ASP.NET 2.0 & VS2005 you will no longer have this problem. All the 'Generated Code' goes away and the designer does not try to format your code for you anymore.
    ~Ryan





    Have I helped you? Please Rate my posts.

  6. #6
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704

    Re: Problem on inheriting from web form

    Well, when VS 2005 comes out he can use templates instead - but the fact is its not due out until late fall.

  7. #7

    Thread Starter
    Hyperactive Member Utpal's Avatar
    Join Date
    Feb 2002
    Location
    Mumbai, India
    Posts
    393

    Re: Problem on inheriting from web form

    Thanks a lot Nemaroller & RDove! What are templates?
    It is easy when you know it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width