trashpanda
trashpanda

Reputation: 93

Issue with OnCLick in ASP.net

Here is the simple redirect function in my cod behind my .aspx file

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}

protected void GoToClicked(object sender, EventArgs e)
{
    Response.Redirect("LoginPage.aspx");
}
}

Pretty basic.

Here is the asp:LinkButton that calls it

<asp:LinkButton ID="LoginLink" runat="server" Text="Login" Font-Bold="true" OnClick="GoToClicked" ></asp:LinkButton>

Whenever I attempt to build I get the following error:

 Error  1   'GoToClicked' is not a member of 'ASP.default_aspx'.       C:\Users\urMom\Documents\Visual Studio 2013\WebSites\HW_2\Default.aspx   65  

What am I doing wrong? I have tried to following:

Using Server.Transfer instead

Changing the function from protected to public

Trying with and without an id tag (both caps and lowercase)

Upvotes: 1

Views: 59

Answers (2)

mason
mason

Reputation: 32694

<asp:LinkButton ID="LoginLink" runat="server" Text="Login" Font-Bold="true" OnClick="GoToClicked"></asp:LinkButton>

Capitalization is important. GoToCLicked should be GoToClicked.

Additionally, the class name in your error message does not line up with the class name shown in your code behind class. You need to make sure these are in sync, double check the @Page directive at the top of your ASPX page.

Upvotes: 5

Jaydip Jadhav
Jaydip Jadhav

Reputation: 12309

Spelling mistake at

Text="Login" Font-Bold="true" OnClick="GoToCLicked" ></asp:LinkButton>
                                    -----^

This should be GoToClicked

Upvotes: 4

Related Questions