I'm having some problems getting a javascript registered on the page so my textbox can fire it on onBlur. I have created a simple test page to demonstrate my problem.
Here is the backend VB.Net
Public Class Test
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Dim scriptText As String = ""
scriptText &= "<script language='javascript'>"
scriptText &= "function DisplayBlurMessage(){alert('you clicked outside the textbox');}"
scriptText &= "</script>"
ClientScript.RegisterClientScriptBlock(Me.GetType(), _
"BlurScript", scriptText, False)
End Sub
End Class
Here is the FrontEnd .aspx file
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Test.aspx.vb" Inherits="WebApplication1.Test" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Test Page</title>
</head>
<body>
<h3>Test Page</h3>
<form id="form1" runat="server">
<asp:TextBox id="TextBox1" columns="54"
Text="Click here then outside"
runat="server" onBlur="DisplayBlurMessage();"/>
</form>
</body>
</html>
When i view the page, clicking out of the textbox, the javascript debugger gives me an error because the javascript isn't defined in the source.
I can however get it to work by putting the Page_Load sub in tags in the aspx file and then accessing the Attributes of the textbox directly. But this is not what I want.
Basically for my final page, I am going to want to iterate through all the textbox's on the page and then give them all a onBlur and onFocus methods that use their id's.
Is this possible? I dont see where I am going wrong.
Please help :(