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.VisualBasicNamespace SalvoPublic Class PromptControl Inherits System.Web.UI.WebControls.HyperLinkImplements IPostBackEventHandler Public Event Prompt(ByVal sender As Object, ByVal e As String) Public Property Message() As String GetReturn ViewState("PromptMessage") End GetSet(ByVal value As String)
ViewState(
"PromptMessage") = value End Set End PropertyPublic Sub New() MyBase.New() End SubProtected 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 SubPublic Sub RaisePostBackEvent(ByVal eventArgument As String) Implements System.Web.UI.IPostBackEventHandler.RaisePostBackEvent RaiseEvent Prompt(Me, eventArgument) End SubEnd ClassEnd
NamespaceThe 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>