troubleshooting Question

ImageButton doesn't fire event

Avatar of accarvajal
accarvajal asked on
8 Comments1 Solution1034 ViewsLast Modified:

I'm using visual studio 2005, ASP.NET with C#. .NET Framework 2.0  but i'm having troubles due to this:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="login.aspx.cs" Inherits="login_login" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="" >
<head runat="server">
    <script language="javascript" src="../scripts/global.js" type="text/javascript"></script>
    <script language="javascript" src="scripts/login.js" type="text/javascript"></script>
    <div id="divImagen">
       <form id="frmLogin" method="post" runat="server" onsubmit="return Validar_Login();" defaultfocus="txtUsuario">
            <asp:Label ID="Label1" runat="server" Font-Bold="True" Text="Usuario" CssClass="lbl"></asp:Label>
            <asp:TextBox ID="txtUsuario" runat="server" CssClass="txt" MaxLength="10" Width="100px"></asp:TextBox>
            <asp:Label ID="Label2" runat="server" Font-Bold="True" Text="Contraseña" CssClass="lbl"></asp:Label>
            <asp:TextBox ID="txtClave" runat="server" CssClass="txt" MaxLength="10" TextMode="Password" Width="100px" EnableViewState="False"></asp:TextBox>
            <asp:ImageButton ID="btnOK" runat="server" ImageUrl="imagenes/botonazulaceptar.gif" CssClass="btn" style="left: 99px; top: 290px" ToolTip="Ingresar" OnClick="btnOK_Click" />
            <asp:ImageButton ID="btnCAMBIAR" runat="server" ImageUrl="imagenes/botonazulcambiar.gif" CssClass="btn" style="left: 27px; top: 324px" ToolTip="Cambiar Contraseña" />

and this is the inherited code in C#:

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class login_login : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)
        if (Page.IsPostBack)

        btnOK.Click += new ImageClickEventHandler(btnOK_Click);

    public void btnOK_Click(object sender, ImageClickEventArgs e)
        string connectionString = ConfigurationManager.AppSettings["connectionString"]; // "Provider=OraOLEDB.Oracle;Data Source=SCRPORTAL;User Id=SCRPORTAL;Password=SCRPORTAL;";
        System.Data.IDbConnection dbConnection = new System.Data.OleDb.OleDbConnection(connectionString);

        string sSQL = "SELECT * FROM USUARIOS WHERE USR_ID = '" + txtUsuario.Text + "'";
        System.Data.IDbCommand dbCommand = new System.Data.OleDb.OleDbCommand();
        dbCommand.CommandText = sSQL;
        dbCommand.Connection = dbConnection;
        System.Data.IDataReader dataReader = dbCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection);
        if (!dataReader.Read())
            Response.Write("<script language='javascript' type='text/javascript'>alert('Usuario no existe');</script>");

problem is, event method called btnOK_Click is not fired by ImageButton named with ID: btnOK, I need to solve this


Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 8 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros