I don't know what is happening but all of a sudden no buttons works on my main page in an asp.net c# application. I tried the same button and procedure on another page and it works perfectly. Where should be the problem?
and code behind
protected void Test(object sender, EventArgs e)
{
txtTest.Attributes["class"] = txtTest.Attributes["class"].Replace("hidden", "");
}
Main page view
<%@ Page Title="Home" Language="C#" MasterPageFile="~/Instruire.Master" AutoEventWireup="true" CodeBehind="Home.aspx.cs" Inherits="Instruire.Home" %>
Autentificare
Utilizator:
Parola:
Tine-ma minte!
code behind
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Instruire
{
public partial class Home : Page
{
private readonly string connString = ConfigurationManager.ConnectionStrings["ConnString"].ConnectionString;
protected void Page_Load(object sender, EventArgs e)
{
if (Session["Marca"] != null)
{
inputMarca.Text = Session["Marca"].ToString();
DivUser.Attributes["class"] = DivUser.Attributes["class"].Replace("hidden", "").Trim();
GetUserData();
DataList1.Attributes.Add("class", "hidden");
}
else
{
inputMarca.Text = string.Empty;
DivUser.Attributes.Add("class", "hidden");
}
if (HttpContext.Current.User != null && HttpContext.Current.User.Identity.IsAuthenticated)
{
DivLogin.Attributes.Add("class", "hidden");
btnActualizare.Attributes["class"] = btnActualizare.Attributes["class"].Replace("hidden", "").Trim();
}
if (Session["SMPSI"] != null)
{
DivLogin.Attributes["class"] = DivLogin.Attributes["class"].Replace("hidden", "").Trim();
DivUser.Attributes.Add("class", "hidden");
}
}
protected void Check_User(object sender, EventArgs e)
{
GetUserData();
}
protected void Test_Redirect(object sender, EventArgs e)
{
Response.Redirect("/UserPages/Testare.aspx");
}
protected void Compartiment(object sender, EventArgs e)
{
}
protected void GetUserData()
{
using (SqlConnection conn = new SqlConnection(connString))
{
string sqlQuery = "SELECT * FROM tblUser WHERE Marca=@Marca";
using (SqlCommand cmd = new SqlCommand(sqlQuery, conn))
{
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@Marca", inputMarca.Text);
conn.Open();
using (SqlDataReader rdr = cmd.ExecuteReader())
{
if (rdr.HasRows)
{
while (rdr.Read())
{
txtMarca.Text = rdr["Marca"].ToString();
txtNume.Text = rdr["Nume"].ToString();
txtPrenume.Text = rdr["Prenume"].ToString();
txtCodCompartiment.Text = rdr["CodCompartiment"].ToString();
txtCompartiment.Text = rdr["Compartiment"].ToString();
txtFunctie.Text = rdr["Functie"].ToString();
}
int id = Convert.ToInt32((inputMarca.Text).ToString());
Session["Marca"] = id;
}
else
{
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Nu este niciun user cu marca asta')", true);
return;
}
}
conn.Close();
}
}
}
protected void Get_All(object sender, EventArgs e)
{
GetAll();
}
private void GetAll()
{
using (SqlConnection conn = new SqlConnection(connString))
{
string sqlQuery = "SELECT * FROM tblUser";
using (SqlCommand cmd = new SqlCommand(sqlQuery, conn))
{
SqlDataAdapter da = new SqlDataAdapter(cmd);
conn.Open();
DataSet ds = new DataSet();
da.Fill(ds);
DataList1.DataSource = ds.Tables[0];
DataList1.DataBind();
}
}
Session.Remove("Marca");
DivUser.Attributes.Add("class", "hidden");
DataList1.Attributes["class"] = DataList1.Attributes["class"].Replace("hidden", "").Trim();
}
protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
{
if (e.CommandName == "click")
{
int id = Convert.ToInt32(DataList1.DataKeys[e.Item.ItemIndex].ToString());
string marca = id.ToString();
Session["Marca"] = marca;
Response.Redirect("/Home.aspx");
}
}
private bool ValidateUser(string userName, string passWord)
{
string lookupPassword = null;
if ((null == userName) || (0 == userName.Length) || (userName.Length > 15))
{
System.Diagnostics.Trace.WriteLine("[ValidateUser] Input validation of userName failed.");
return false;
}
if ((null == passWord) || (0 == passWord.Length) || (passWord.Length > 25))
{
System.Diagnostics.Trace.WriteLine("[ValidateUser] Input validation of passWord failed.");
return false;
}
try
{
using (SqlConnection conn = new SqlConnection(connString))
{
conn.Open();
string sqlQuery = "SELECT password FROM tblAdmin WHERE username=@userName";
using (SqlCommand cmd = new SqlCommand(sqlQuery, conn))
{
cmd.Parameters.Add("@userName", SqlDbType.VarChar, 25);
cmd.Parameters["@userName"].Value = userName;
lookupPassword = (string)cmd.ExecuteScalar();
cmd.Dispose();
}
conn.Dispose();
}
}
catch (Exception ex)
{
System.Diagnostics.Trace.WriteLine("[ValidateUser] Exception " + ex.Message);
}
if (null == lookupPassword)
{
return false;
}
return (0 == string.Compare(lookupPassword, passWord, false));
}
protected void BTNLogin(object sender, EventArgs e)
{
if (ValidateUser(txtUserName.Text, txtUserPass.Text))
FormsAuthentication.SetAuthCookie(txtUserName.Text, chkPersistCookie.Checked);
Response.Redirect("Home.aspx");
}
protected void Test(object sender, EventArgs e)
{
txtTest.Attributes["class"] = txtTest.Attributes["class"].Replace("hidden", "");
}
}
}
Marius VasilePosted Aug 24, 2023, 1:13 PM
I moved login form on a login.aspx page and now there are no issues
Marius VasilePosted Aug 24, 2023, 12:55 PM
Ok, it seems that using class=hidden for Login Div doesn't prevent the login form from being active and prevent other buttons from firing. Changind to visible=false fixed it but I am not happy with the resolve