Asp.net 用户控件添加自定义事件(2)
Width="56px" /></td>
<td style="width: 100px; text-align: center">
<asp:Button ID="Button2" runat="server" Text="登出" Width="54px" /></td>
</tr>
</table>
用户控件后台代码
public event EventHandler Authenticate;
protected void Page_Load(object sender, EventArgs e)
{
}
public void Button1_Click(object sender, EventArgs e)
{
if (Authenticate!=null)
{
Authenticate(this, new EventArgs());//如果用户自定义添加了事件,则该button会按指定的事件进行,而不会走默认事件。相反,会执行默认事件。
}
else
{
string connectString = "Server=. ; DataBase=Test ; uid=sa ; pwd=cosecose ";
string selectString = "Select * from userInfo where Name='" + txtName.Text.ToString() + "' and Password='" + txtPassword.Text.ToString() + "'";
SqlConnection conn = new SqlConnection(connectString);
conn.Open();
SqlCommand cmd = new SqlCommand(selectString, conn);
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand = cmd;
DataTable dt = new DataTable();
sda.Fill(dt);
if (dt.Rows.Count == 0)
{
Response.Write("<script>window.alert('密码或用户名输入错误!')</script>");
}
else
{
相关新闻>>
- 发表评论
-
- 最新评论 更多>>