Home All Groups Group Topic Archive Search About
Author
26 Jan 2006 9:16 PM
Wayne Wengert
I am attempting to check the status of a login (Login1) which is containted
within a login view (lv1) using the following code but each of the 2 Dim
statements get flagged with"End of Statement expected"? What is the correct
way to do this?

=============================
Protected Sub Login1_LoginError(ByVal sender As Object, ByVal e As
System.EventArgs)

Dim currlogin As Login = lv1.FindControl("Login1") as Login

Dim membername As String = currlogin.FindControl("UserName") as String

If membername.IsApproved Then

Exit Sub

Else 'User Not Yet Approved

currlogin.FailureText = "User has not been authorized yet."

End If

End Sub

Author
28 Jan 2006 1:00 PM
Teemu Keiski
C# has 'as' keyword for trycasting, In VB2005 same is TryCast.


Dim currlogin As Login = TryCast(lv1.FindControl("Login1"),  Login)

If Not IsNothing(currLogin) Then
    'Access Login object here
End If


--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke

Show quoteHide quote
"Wayne Wengert" <wayneSKIPSPAM@wengert.org> wrote in message
news:O6dS52rIGHA.1848@TK2MSFTNGP12.phx.gbl...
>I am attempting to check the status of a login (Login1) which is containted
>within a login view (lv1) using the following code but each of the 2 Dim
>statements get flagged with"End of Statement expected"? What is the correct
>way to do this?
>
> =============================
> Protected Sub Login1_LoginError(ByVal sender As Object, ByVal e As
> System.EventArgs)
>
> Dim currlogin As Login = lv1.FindControl("Login1") as Login
>
> Dim membername As String = currlogin.FindControl("UserName") as String
>
> If membername.IsApproved Then
>
> Exit Sub
>
> Else 'User Not Yet Approved
>
> currlogin.FailureText = "User has not been authorized yet."
>
> End If
>
> End Sub
>
>
Author
29 Jan 2006 6:50 PM
DWS
Wayne,
Controls are cool but here's easier way to check if a user is logged in.  It
also works on pages without login controls incase you have a seperate login
page.

If Page.User.Identity.IsAuthenticated Then
       label1.text = "Welcome " &    Page.User.Identity.Name
else
       label1.text = "User not authorized, you need to sign in"
End If

Good Luck
DWS

Show quoteHide quote
"Wayne Wengert" wrote:

> I am attempting to check the status of a login (Login1) which is containted
> within a login view (lv1) using the following code but each of the 2 Dim
> statements get flagged with"End of Statement expected"? What is the correct
> way to do this?
>
> =============================
> Protected Sub Login1_LoginError(ByVal sender As Object, ByVal e As
> System.EventArgs)
>
> Dim currlogin As Login = lv1.FindControl("Login1") as Login
>
> Dim membername As String = currlogin.FindControl("UserName") as String
>
> If membername.IsApproved Then
>
> Exit Sub
>
> Else 'User Not Yet Approved
>
> currlogin.FailureText = "User has not been authorized yet."
>
> End If
>
> End Sub
>
>
>