CodeMantle
CodeMantle

Reputation: 1426

How can I obtain a control's Handle in a ASP.NET VB project?

I want to add Cue/Watermarks to my ASP:TextBox controls for a nicer user experience, and came across the very nice CueProvider, which has this VB-adjusted version which sadly I cannot compile.

My class is as follows

#Region "Imports"
Imports System.Runtime.InteropServices
#End Region

Public Class Watermark

<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)>
Private Shared Function SendMessage(ByVal hWnd As HandleRef,
                                    ByVal Msg As UInteger,
                                    ByVal wParam As IntPtr,
                                    ByVal lParam As String) As IntPtr
End Function

Public Shared Sub [Set](ByVal ctl As Control, ByVal hintText As String)

    Const EM_SETCUEBANNER As Int32 = &H1501

    Dim retainOnFocus As IntPtr = New IntPtr(1)
    Dim msg As Int32 = EM_SETCUEBANNER

    SendMessage(New HandleRef(ctl, ctl.Handle), msg, retainOnFocus, hintText)

End Sub

End Class

The compile failure is on the New HandleRef(ctl, ctl.Handle) that second parameter is apparently not a valid property.

How I can get the windows handle of the incoming UI control?

Upvotes: 1

Views: 70

Answers (1)

mason
mason

Reputation: 32694

The code you have found is for Windows Forms, but you are developing an ASP.NET Web Forms application. Therefore it is not appropriate. You cannot obtain a window handle in ASP.NET.

I believe what you're after is a placeholder.

<input type="text" placeholder="First Name" />

Or if you need a server control,

<asp:TextBox runat="server" placeholder="First Name" />

Upvotes: 2

Related Questions