asp.net Button Error

kadir koçaslan 65 Reputation points
2023-02-14T10:56:40.71+00:00

button gives error like this

CS1061: 'web_holding_adminpanel_masterpage_spotadd_aspx' does not contain a definition for 'btnSave_Click' and no accessible extension method 'btnSave_Click' accepting a first argument of type 'web_holding_adminpanel_masterpage_spotadd_aspx' could be found (are you missing a using directive or an assembly reference?)

  <table class="w-100">
            <tr>
                <td style="width: 374px">
                    <asp:Label ID="Label2" runat="server" Text="Ad Soyad:"></asp:Label>
                </td>
                <td>
                    <asp:TextBox ID="txtAdSoyad" class="form-control form-control-lg" runat="server" Width="100%"></asp:TextBox>
                </td>
                <td>&nbsp;</td>
            </tr>
            <tr>
                <td style="width: 374px">
                    <asp:Label ID="Label3" runat="server" Text="Görev:"></asp:Label>
                </td>
                <td>
                    <asp:TextBox ID="txtGorev" class="form-control form-control-lg" runat="server" Width="100%"></asp:TextBox>
                </td>
                <td>&nbsp;</td>
            </tr>
            <tr>
                <td style="width: 374px">
                    <asp:Label ID="Label4" runat="server" Text="Metin:"></asp:Label>
                </td>
                <td>
                    <asp:TextBox class="form-control form-control-lg" ID="txtMetin" runat="server" Width="100%"></asp:TextBox>
                </td>
                <td>&nbsp;</td>
            </tr>
            <tr>
                <td style="height: 23px; width: 374px">
                    <asp:Label ID="Label5" runat="server" Text="Resim:"></asp:Label>
                </td>
                <td style="height: 23px">
                    <asp:FileUpload ID="fuİmage" runat="server" class="form-control form-control-lg" />
                </td>
                <td style="height: 23px"></td>
            </tr>
            <tr>
                <td style="width: 374px">&nbsp;</td>
                <td>
                    <asp:Button ID="btnSave" class="btn btn-info" runat="server" Text="Kaydet" OnClick="btnSave_Click" />
                </td>
                <td>&nbsp;</td>
            </tr>
            <tr>
                <td style="width: 374px">&nbsp;</td>
                <td>
                    <asp:Label ID="lblMessage" runat="server"></asp:Label>
                </td>
                <td>&nbsp;</td>
            </tr>
        </table>

I ask for your help

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,598 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,339 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Viorel 120.4K Reputation points
    2023-02-14T11:53:49.79+00:00

    Go to the spotadd.aspx.cs file (or maybe web_holding_adminpanel_masterpage_spotadd.aspx.cs; you can use the Solution Explorer to open the code file), and add a function to your class:

    protected void btnSave_Click( object sender, EventArgs e )
    {
    
    }
    

    It will be called when you press the "Kaydet" button. You should also implement this function.

    0 comments No comments

  2. Lan Huang-MSFT 30,176 Reputation points Microsoft External Staff
    2023-02-15T02:10:23.14+00:00

    Hi @kadir koçaslan,
    User's image

    As the error message says, it is a problem with the btnSave Button.

    You use the onclick event in the front end, but you don't match the corresponding event handler in the back end code.

    https://learn.microsoft.com/en-us/dotnet/api/system.web.ui.webcontrols.button.onclick?view=netframework-4.8.1

    protected void btnSave_Click(object sender, EventArgs e){}

    Best regards,
    Lan Huang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.