Friday, October 19, 2012

Cannot convert type ASP.login_aspx to System.Web.UI.WebControls.Login

Cannot convert type ASP.login_aspx to System.Web.UI.WebControls.Login

Problem

You get following error when you run ASP.Net login page
1.Cannot convert type ASP.login_aspx to System.Web.UI.WebControls.Login

Solution


  • Go to your login.aspx.cs code behind file.
  • Find line where page class is defined.
    1.public partial class Login : System.Web.UI.Page
  • Rename this class to something else. For example,
    1.public partial class clsLogin : System.Web.UI.Page
  • Now go to your webform code in login.aspx file. And change inherit attribute to point to clsLogin class.
    1.<%@ Page Language="C#" ValidateRequest="false" AutoEventWireup="true"
    2.CodeFile="Login.aspx.cs" Inherits="Login" %>

    Change this to,
    1.<%@ Page Language="C#" ValidateRequest="false" AutoEventWireup="true"
    2.CodeFile="Login.aspx.cs" Inherits="clsLogin" %>
Note how Inherits="Login" is changed to Inherits="clsLogin" above

This should solve your problem

Cause

Login is treated as a reserve word in ASP.Net. If you use it for your class name, it conflicts with existing ASP.Net Login class.

No comments:

Post a Comment