|
-
Mar 30th, 2004, 04:43 PM
#1
Thread Starter
Frenzied Member
Default CssClass on Custom Control
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
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
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.
Being educated does not make you intelligent.
Need a weekend getaway??? Come Visit
-
Mar 30th, 2004, 11:01 PM
#2
I wonder how many charact
A few suggestions:
Remove the If disabled readonly from your script functions, and see if it works...
Turn on IE script debugging (check the web), and when that page loads, choose Running Documents , and select the page... put a breakpoint on the line containing the start of the focus javascript function. Use Quickwatch and etc to see that value of this (or if inaccessible, use command window, and '? this.value'.
I have a feeling the 'this' isn't exactly what you may think it is. Or, the functions are not being called.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|