I am creating a custom ASP.NET textbox control and I am trying to set the default CssClass, but I can't figure out how.
I have added attributes to the controls (OnBlur and OnFocus) those work fine changing the cssClass, but when the page initially loads the textbox doesn't have a default cssClass.
Here's my code
If I just type formBox as the CssClass into the controls properties, it works fine, but I can't set it in the code above for some reason.VB Code:
Imports System Imports System.Web Imports System.Web.UI Imports System.Web.UI.WebControls Imports System.ComponentModel Namespace JHATextBox Public Class JHATextBox Inherits TextBox 'This should be the default cssClass when the page loads. Private _cssClass As String = "formBox" Protected Overrides Sub Render(ByVal writer As HtmlTextWriter) Dim strScript As String = "" If Page.IsClientScriptBlockRegistered("ClientScript") = False Then strScript &= "<script language=""javascript"" type=""text/javascript"">" & vbCrLf strScript &= vbTab & "function activeField(ptr){" & vbCrLf strScript &= vbTab & vbTab & "if((ptr.disabled != true) && (ptr.readOnly != true)) {" & vbCrLf strScript &= vbTab & vbTab & vbTab & "ptr.className = 'formBoxSelected';" & vbCrLf strScript &= vbTab & vbTab & "}" & vbCrLf strScript &= vbTab & "}" & vbCrLf strScript &= vbTab & "function inactiveField(ptr) {" & vbCrLf strScript &= vbTab & vbTab & "if((ptr.disabled != true) && (ptr.readOnly != true)) {" & vbCrLf strScript &= vbTab & vbTab & vbTab & "ptr.className = 'formBox';" & vbCrLf strScript &= vbTab & vbTab & "}" & vbCrLf strScript &= vbTab & "}" & vbCrLf strScript &= "</script>" & vbCrLf Page.RegisterStartupScript("ClientScript", strScript) End If writer.AddAttribute("onBlur", "void inactiveField(this);") writer.AddAttribute("onFocus", "void activeField(this);") writer.RenderBeginTag("input") writer.RenderEndTag() End Sub Public Overrides Property CssClass() As String Get Return _cssClass End Get Set(ByVal Value As String) _cssClass = Value End Set End Property End Class End Namespace




Reply With Quote