C# 名称“btnupdate”在c中的当前上下文中不存在
这是我的CSF文件:C# 名称“btnupdate”在c中的当前上下文中不存在,c#,C#,这是我的CSF文件: protected void GridViewStudent_SelectedIndexChanged(object sender, EventArgs e) { btnupdate.Visible = true; } protected void btnupdate_Click(object sender, EventArgs e) { try
protected void GridViewStudent_SelectedIndexChanged(object sender, EventArgs e)
{
btnupdate.Visible = true;
}
protected void btnupdate_Click(object sender, EventArgs e)
{
try
{
OleDbConnection con = Connection.DBconnection();
con.Open();
string SID = lblSID.Text;
OleDbCommand com = new OleDbCommand("UPDATE registration set(username=@username,pwd=@pwd;address=@address,phone=@phone,email=@email,qualification=@qualification where SID=@SID", con);
com.Parameters.AddWithValue("@username", Textusername.Text.Trim());
com.Parameters.AddWithValue("@pwd", Textpwd.Text.Trim());
com.Parameters.AddWithValue("@email", Textemail.Text.Trim());
com.Parameters.AddWithValue("@phone", Textphone.Text.Trim());
com.Parameters.AddWithValue("@address", Textaddress.Text.Trim());
com.Parameters.AddWithValue("@qualification", Textqualification.Text.Trim());
com.Parameters.AddWithValue("SID", SID);
com.ExecuteNonQuery();
com.Dispose();
ShowMessage("Student Data update Successfully......!");
GridViewUser.EditIndex = -1;
BindGridView();
btnupdate.Visible = false;
}
catch (Exception ex)
{
ShowMessage(ex.Message);
}
finally
{
OleDbConnection con = new OleDbConnection(connectionstr);
if (con.State == ConnectionState.Open)
{
con.Close();
}
}
}
aspx文件:
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="registrationuser.aspx.cs" Inherits="registration.registrationuser" %>
<asp:Button ID="btnupdate" runat="server" Text="Update" visible="false" OnClick="btnupdate_Click"Height="30px" Width="75px" Font-Size="15px" ForeColor="#0094ff" BackColor="white" />
当我运行上面的代码时,它会显示如下错误
当前上下文中不存在名称“btnupdate”
我是.net新手,请不要介意我的代码中有任何错误
你能指导我解决这个问题吗
谢谢,您能看看您的.ascx.designer.cs并告诉我们那里是否有BTNU更新吗
我建议您删除此对象并重新创建它。您提到该控件未出现在设计器文件中。您使用的是Visual Studio吗?这是一个ASP.NET Web应用程序吗 如果是,那么您可以尝试以下方法: 在解决方案资源管理器中,您可以右键单击包含受影响文件的项目,然后选择“转换为Web应用程序”。这将强制Visual Studio重新创建项目中的所有设计器文件 请注意,根据您的配置,转换会将指向.cs文件的CodeFile属性更改为.ascx页面顶部的Codebehind属性。根据我的经验,为了让我的项目正常运行,我不得不将其改回代码文件
我已经对这种错误进行了多次搜索,但我无法找出为什么在保存对.ascx文件所做的更改时设计器文件有时不更新。您想实现什么?还检查了一次,确保此处有空格:OnClick=btnupdate\u ClickHeight=30px@devlincarnate:仍然保持不变…你的最终对我来说没有任何意义,为什么要创建一个新连接,然后在它打开时立即关闭它,这可能不是吗?不,btnupdate不在.ascx.designer.cs中。。我可以知道,如何重新创建吗?只需从您的页面中删除当前的一个,保存,然后创建另一个同名的,如果不工作,也更改名称哈哈。