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:
Public Class WFrmEnt
Inherits System.Web.UI.Page
Protected WithEvents nLast As System.Web.UI.WebControls.ImageButton
Protected WithEvents nNext As System.Web.UI.WebControls.ImageButton
Protected WithEvents nPrev As System.Web.UI.WebControls.ImageButton
Protected WithEvents nCancel As System.Web.UI.WebControls.Button
Protected WithEvents nSave As System.Web.UI.WebControls.Button
Protected WithEvents nMessage As System.Web.UI.WebControls.Label
Protected WithEvents nDelete As System.Web.UI.WebControls.Button
Protected WithEvents nModify As System.Web.UI.WebControls.Button
Protected WithEvents nAdd As System.Web.UI.WebControls.Button
Protected WithEvents nPrint As System.Web.UI.WebControls.Button
Protected WithEvents nFilter As System.Web.UI.WebControls.Button
Protected WithEvents nFirst As System.Web.UI.WebControls.ImageButton
Protected WithEvents nRemoveFilter As System.Web.UI.WebControls.Button
Private Sub nFirst_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles
nFirst.Click
Navigate(CNavAction.First)
End Sub
Private Sub nPrev_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles nPrev.Click
Navigate(CNavAction.Prev)
End Sub
Private Sub nNext_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles nNext.Click
Navigate(CNavAction.Next)
End Sub
Private Sub nLast_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles nLast.Click
Navigate(CNavAction.Last)
End Sub
Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
MyBase.Render(writer)
End Sub
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:
Protected WithEvents nLast As System.Web.UI.WebControls.ImageButton
Protected WithEvents nNext As System.Web.UI.WebControls.ImageButton
Protected WithEvents nPrev As System.Web.UI.WebControls.ImageButton
Protected WithEvents nCancel As System.Web.UI.WebControls.Button
Protected WithEvents nSave As System.Web.UI.WebControls.Button
Protected WithEvents nMessage As System.Web.UI.WebControls.Label
Protected WithEvents nDelete As System.Web.UI.WebControls.Button
Protected WithEvents nModify As System.Web.UI.WebControls.Button
Protected WithEvents nAdd As System.Web.UI.WebControls.Button
Protected WithEvents nPrint As System.Web.UI.WebControls.Button
Protected WithEvents nFilter As System.Web.UI.WebControls.Button
Protected WithEvents nFirst As System.Web.UI.WebControls.ImageButton
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?
Re: Problem on inheriting from web form
Am I using the right technique of programming?
Re: Problem on inheriting from web form
Does anybody inherit from web forms, or am I the only one doing it? Please somebody answer!
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.
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.
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.
Re: Problem on inheriting from web form
Thanks a lot Nemaroller & RDove! What are templates?