0

Here is my csfile:

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 file:

<%@ 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" />

When i run the above code,it shows error like this,

The name 'btnupdate' doesn't exist in current context

I m new to .net, please don't mind if any mistake in my code.

Can you please guide me to fix this issue?

Thanks,

pcs
  • 1,864
  • 4
  • 25
  • 49
  • What are you trying to achieve? Also have you checked once http://stackoverflow.com/questions/706603/the-name-controlname-does-not-exist-in-the-current-context –  Oct 27 '15 at 17:28
  • http://stackoverflow.com/questions/706603/the-name-controlname-does-not-exist-in-the-current-context – Jonathan Carroll Oct 27 '15 at 17:30
  • 1
    make sure you have a space here: `OnClick="btnupdate_Click"Height="30px"` – devlin carnate Oct 27 '15 at 17:32
  • @devlincarnate: still stays same .... – pcs Oct 27 '15 at 17:33
  • The error occurs when you _run_ or when you _compile_? Is that the _only_ error or are there others? – D Stanley Oct 27 '15 at 17:33
  • when i hit ctrl+shift+B.... – pcs Oct 27 '15 at 17:34
  • @JonathanCarroll: I checked your link, in that the name 'btnupdate' doesn't exist in current context should same.. so my page also same.. – pcs Oct 27 '15 at 17:34
  • 1
    Your "finally" doesn't make any sense to me, why create a new connection and then immediately close it (if its open, which its probably not)? – Ron Beyer Oct 27 '15 at 17:41
  • @RonBeyer: I just removed that code, and still stays same issue.. – pcs Oct 27 '15 at 17:43
  • @Rani I wasn't suggesting it had anything to do with your problem, I was just noting my confusion over what you were trying to accomplish there. – Ron Beyer Oct 27 '15 at 17:44
  • @Rani Is your button inside an `asp:Content` control, like this?`...` – rlb.usa Oct 27 '15 at 17:44
  • @rlb.usa: yes.. inside the content only.. – pcs Oct 27 '15 at 17:47
  • @Rani Just try it... stop running website (if it running), change the update button id i.e ) btnUpdate to anything. **Save the changes**. then undo the change. Again **Save the changes**. hope this helps.. – Sankar Oct 28 '15 at 12:29

2 Answers2

0

Can you have a look on your .ascx.designer.cs and tell us if has an btnupdate there?

I suggest you to delete this object and recreate it.

0

You mention that the control isn't appearing in your designer file. Are you using Visual Studio, and is this an ASP.NET Web Application?

If so, then you can try this:

In the solution explorer you can right click on the project that contains the affected file and select 'Convert to Web Application'. This will force Visual Studio to recreate all of the designer files in the project.

Do note that depending on your configuration, the conversion will change the CodeFile property that points to the .cs file to be a Codebehind property at the top of your .ascx page. In my experience, I've had to change this back to being CodeFile in order to get my project to run correctly.

I've done several searches into this kind of error, but I haven't been able to figure out why the designer files sometimes don't update when saving changes made to the .ascx file.

G3n0c1de
  • 139
  • 2
  • 14