gpt4 book ai didi

c# - ASP.net 中文本框的占位符

转载 作者:太空宇宙 更新时间:2023-11-03 23:18:27 29 4
gpt4 key购买 nike

需要一个占位符来显示文本框的文本,当我在文本框中单击或输入文本时该文本消失

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;



public partial class SIGNUPaspx : System.Web.UI.Page
{

protected void Page_Load(object sender, EventArgs e)
{

}

protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Admin\Documents\Visual Studio 2010\WebSites\my website\App_Data\GYMDatabase.mdf;Integrated Security=True;User Instance=True");
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "select * from Client_Data Where C_Email='" + TextBox6.Text + "'";
cmd.Connection = con;
SqlDataReader rd = cmd.ExecuteReader();
rd.Read();
if (rd.HasRows)
{
Label1.Text = "Email Already Exist";
}
else
{
SqlConnection con1 = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Admin\Documents\Visual Studio 2010\WebSites\my website\App_Data\GYMDatabase.mdf;Integrated Security=True;User Instance=True");
con1.Open();
String str = "INSERT INTO Client_Data(C_FName,C_LName,C_Address,C_Gender,C_Email,C_Password,C_MobileNo,C_RegistrationCode) VALUES ('" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox8.Text + "','" + RadioButtonList1.Text + "','" + TextBox6.Text + "','" + TextBox4.Text + "','" + TextBox7.Text + "','" + TextBox5.Text + "')";
SqlCommand cm = new SqlCommand(str, con1);
String str1 = "INSERT INTO PaymentTable(C_Email) VALUES ('" + TextBox6.Text + "')";
SqlCommand cmp = new SqlCommand(str1, con1);
cm.ExecuteNonQuery();
cmp.ExecuteNonQuery();
con.Close();
Label1.Visible = true;
Response.AddHeader("REFRESH", "3;URL=LOGIN.aspx");
}
rd.Close();
con.Close();

}
private void TextBox1_Enter(object sender, EventArgs e)
{
if (TextBox1.Text == "First Name")
{
TextBox1.Text = "";
}
}
private void TextBox1_Leave(object sender, EventArgs e)
{

if (TextBox1.Text == "")
{
TextBox1.Text = "First Name";
TextBox1.ForeColor = System.Drawing.Color.LightGray;
}
}

}

最佳答案

您不需要在 C# 中执行所有这些操作。只需在 TextBox 中添加占位符属性

<asp:TextBox ID="UserName" runat="server" CssClass="form-control" placeholder="Username or Email" Width="350"></asp:TextBox>

关于c# - ASP.net 中文本框的占位符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36369864/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com