Prompt Control

I have been doing a little experiment with custom control in asp.net. So, I think...what I can do if I have a web page where I can't put a textbox ? Simple, the solution to my problem is the javascript prompt function. So, I'v created a simple control for prompting where a user click a text.

The code of prompt control:

Imports Microsoft.VisualBasic

Namespace Salvo

 

Public Class PromptControl

Inherits System.Web.UI.WebControls.HyperLink

Implements IPostBackEventHandler

Public Event Prompt(ByVal sender As Object, ByVal e As String)

Public Property Message() As String

Get

Return ViewState("PromptMessage")

End Get

Set(ByVal value As String)

ViewState("PromptMessage") = value

End Set

End Property

Public Sub New()

MyBase.New()

End Sub

Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)

Page.ClientScript.GetPostBackEventReference(Me, "")

Me.Attributes.Add("onclick", "__doPostBack('" & Me.ClientID & "',prompt('" & Message & "'));")

MyBase.Render(writer)

End Sub

Public Sub RaisePostBackEvent(ByVal eventArgument As String) Implements System.Web.UI.IPostBackEventHandler.RaisePostBackEvent

RaiseEvent Prompt(Me, eventArgument)

End Sub

End Class

End Namespace

 

The code of web page:

<%@ Page Language="VB" %>

<%@ Register Namespace="Salvo" TagPrefix="SA" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

Protected Sub AlertMe(ByVal sender As Object, ByVal message As String)

Page.ClientScript.RegisterStartupScript(Me.GetType, "promptMessage", "alert('What you have typed in prompt is " & message & "');", True)

End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

<title></title>

</head>

<body>

<form id="form1" runat="server">

<div>

<SA:PromptControl runat="server" ID="A" Text="Prompt me" Message="Input what you want!" OnPrompt="AlertMe" ></SA:PromptControl>

</div>

</form>

</body>

</html>

 

No Comments