Click here to Skip to main content
15,892,537 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I encountered this error:
I Cannot implicitly convert type "System.Web.UI.WebControls.LoginView" to "Login"

Line 26:         Login Login1 = (System.Web.UI.WebControls.LoginView)LoginView1.FindControl("Login1");

Line 27:             TextBox UserName = (TextBox)Login1.FindControl("UserName");
Line 28:             TextBox FailureText = (TextBox)Login1.FindControl("FailureText");



and I had declare the following as my namespaces. But errors still remain.
C#
using System.Web.UI;
using System.Web.UI.WebControls;


Can anyone give me a suggestion??

Thanks and appreciated. (:
Posted
Comments
[no name] 25-Jun-12 11:13am    
What type of control is "Login1"? Where is that declared?
mathidioticz 25-Jun-12 11:20am    
Login1 is asp.net drag and drop login control. Login1 is build inside LoginView.
The error code are inside the login.aspx.cs file

1 solution

Error clearly lies here:
C#
Login Login1 = (System.Web.UI.WebControls.LoginView)LoginView1.FindControl("Login1");

You are trying to cast a "Login" control into "LoginView". You can clearly see that you are trying to find a control inside 'LoginView'(child control) but then trying to cast it to parent.

Change it to:
C#
Login Login1 = (System.Web.UI.WebControls.Login)LoginView1.FindControl("Login1");
to resolve it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900