Note that there are some explanatory texts on larger screens.

plurals
  1. POASP.NET Javascript Textbox onblur
    primarykey
    data
    text
    <p>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. </p> <p>Here is the backend VB.Net</p> <pre><code>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 &amp;= "&lt;script language='javascript'&gt;" scriptText &amp;= "function DisplayBlurMessage(){alert('you clicked outside the textbox');}" scriptText &amp;= "&lt;/script&gt;" ClientScript.RegisterClientScriptBlock(Me.GetType(), _ "BlurScript", scriptText, False) End Sub End Class </code></pre> <p>Here is the FrontEnd .aspx file</p> <pre><code>&lt;%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Test.aspx.vb" Inherits="WebApplication1.Test" %&gt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml" &gt; &lt;head&gt; &lt;title&gt;Test Page&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;h3&gt;Test Page&lt;/h3&gt; &lt;form id="form1" runat="server"&gt; &lt;asp:TextBox id="TextBox1" columns="54" Text="Click here then outside" runat="server" onBlur="DisplayBlurMessage();"/&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>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. </p> <p>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. </p> <p>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.</p> <p>Is this possible? I dont see where I am going wrong.</p> <p>Please help :(</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload