tags:

views:

655

answers:

8

Hi, I'm pretty new to this, infact this is my first post.

I'm using Visual Studio 2005. On my .aspx page, I have a 'loginStatus' control so the user can logout of a page which works well. However the 'loginStatus' control is not a button, it's text ("logout"). Is it possible to make this into a button?

Here is the line of code:

<asp:LoginStatus ID="LoginStatus1" runat="server" OnLoggingOut="LoginStatus1_LoggingOut" />

Would I just add some style somehow? If so, please help me.

Thanks.

A: 

Using JavaScript:

Grab the url of the link and add a button which, when onclick'ed, points the browser to that url. Then add display:none to the original link with CSS.

You can also use an image as Colin says, but that would fake a button and I assume you want a real button.

Time Machine
A real button would be the ideal option rather than an image.I think I will use your idea, thanks.
A: 

YOu could try to render it using an Image, as stated here

The LoginStatus control displays either a text or an image link, depending on the setting of the LoginImageUrl and LogoutImageUrl properties. You can display either text or images for one or both states.

Colin
A: 

Cheers, I will have a look into this :)

I think it's strange that the option of turning it into a button is not already available.

Yo, welcome to StackOverflow! But for comments like this, use the "add comment" operation :)
Peter Lillevold
A: 

You could wrap the LoginStatus inside of a LinkButton (Or any kind of button).

<asp:LinkButton id="LinkButton1" runat="server">
    <asp:LoginStatus id="LoginStatus1" runat="server" />
</asp:LinkButton>

then use the LinkButton1 events.

Chris
This will disable the build in functionality for the LoginStatus, which is perhaps not what he wants...?
awe
A: 

You could always just extend the LoginStatus control by creating a derived class, and overriding the rendering behaviour to change the output elements into your desired elements, or add style attributes, or whatever.

(apologies for VB)


Public Class MyLoginStatus
    Inherits System.Web.UI.WebControls.LoginStatus

    Public Overrides Sub RenderBeginTag(ByVal writer As System.Web.UI.HtmlTextWriter)

        writer.AddStyleAttribute("display", "none")
        MyBase.RenderBeginTag(writer)

    End Sub

End Class

This kind of behaviour could be extended to turn the output into a button, if you so wish, either in aggregate (modifying the final rendered output by creating your own HtmlTextWriter enclosing a StringWriter and invoking the base methods), or by injecting your own behaviour into the relevant render events.

Rabid
A: 

Have you looked into Control Adapters - this allows you to alter the HTML generated. It's primarily used for adapting HTML for different browsers and devices, but can be used to have complete control over server controls.

Lee

Lee Atkinson
+3  A: 

Haven't tested this, but it might solve your problem : forum post

Otherwise you might use jQuery to solve this. (I think...)

Thomas Sandberg
A: 

Just use LoginImageUrl or LogoutImageUrl

<asp:LoginStatus runat="server"
LogoutImageUrl="~/App_Themes/Theme1/Images/logout.png"
LoginImageUrl="~/App_Themes/Theme1/Images/login.png" />
jlp