how to remove 'name' attribute from server controls?

前端 未结 6 2110
别那么骄傲
别那么骄傲 2020-11-29 11:19

The following asp.net side code of control:


6条回答
  •  青春惊慌失措
    2020-11-29 11:53

    Setting EnableViewState="False" will slim down the name. You can also make a class that inherits the Textbox Control and override the Render procedure to not include the name.

    Public Class CustomTextBox
        Inherits TextBox
        Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
            MyBase.Render(writer)
            'Simplified rendering of control...
            writer.WriteLine("")        
        End Sub
    End Class
    
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
         Dim MyCustomTextBox As New CustomTextBox
         form1.Controls.Add(MyCustomTextBox)
    End Sub
    

    Alternatively, if you don't want to have to add the control at run-time, you can make your CustomTextBox as a ServerControl so that you can add it at design time.

提交回复
热议问题