onchange event not working in combination with requiredfieldvalidator control

Last post 05-09-2008 9:40 AM by dits59. 1 replies.

Sort Posts:

  • onchange event not working in combination with requiredfieldvalidator control

    05-09-2008, 7:48 AM
    • Loading...
    • tomgrillo
    • Joined on 03-30-2007, 6:14 PM
    • Posts 3

     Hi,

     I need some help. Below a simple testpage with a texbox a button and an image. What I want to achieve is to change the src of the image (id=imgImage) whenever the content of the textbox (id=txtBox) is changed. Very basic stuff ... I've added a javascript function (on page load, see below) to add a javascript command to the 'onchange' event of the textbox and it's working fine.

    However, when I add a requiredfieldvalidator to that same textbox it's not working anymore. I've been looking for a solution but can't seem to find what's wrong!! I'm sure it has to do with the additional javascript the requiredfieldvalidator is generating but I don't know what. If I change the javascript to a simple alert command it works (with the requiredfieldvalidator) but changing the src property only works without the requiredfieldvalidator ....

     Any help would be very appriciated.

    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Validation.aspx.vb" Inherits="Validation" %>

    <!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 runat="server">

    <title>Untitled Page</title>

    </head>

    <body>

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

    <div>

    <asp:Image runat="server" ID="imgImage" ImageUrl="~/bullet.gif" />

    <asp:TextBox runat="server" ID="txtBox" />

    <asp:RequiredFieldValidator runat="server" ID="rqvVal" ControlToValidate="txtBox"

    ErrorMessage="Invalid!" />

    <asp:Button runat="server" ID="btnButton" Text="Dummy" />

    </div>

    </form>

    </body>

    </html>

     

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    Dim strJava As String

    strJava = "javascript:getElementById('" + [imgImage].ClientID + "').src='tips.gif';"

    [txtBox].Attributes.Add("onchange", strJava)

    End Sub

    Tom Grillo
  • Re: onchange event not working in combination with requiredfieldvalidator control

    05-09-2008, 9:40 AM
    • Loading...
    • dits59
    • Joined on 06-25-2006, 1:54 PM
    • Posts 18
    use document.getElementById instead of getElementById
Page 1 of 1 (2 items)