I'm working on a project where I'm using the <%= getString("key")%> to dynamically get the appropriate text.
this works great when i use it in simple p tags, but i can't find a way to do this with controls like Button/Label etc.
Is there any way, other than calling
Mybutton.Text = getstring("key");
to dynamically add the text?
The idea is that getString retrieves af language code, and depending on that code gets a string in the appropiate language.
I've been looking around, but all i come across is using the embedded code tags directly in the aspx pages, which wont cut it for buttontext.
If you can use DataBinding instead of the <%= operator, you can use:
<asp:Button ID="MyButton" Text='<%# getstring("key") %>' />
This is a good explanation of why <%= won't work in this context.
i have the following problem:
i work in web application and only today. any control i put on the page, when trying to access it from behind code. it doesn't appear at all. what are the probabilities and reasons for this problem.
note:
i work from a thin client. they make some maintenance on their server today. and after that i find this problem.
the previous controls on my page can be accessed normally with out any problems.
See if the controls have an ID this might sound stupid but perhaps yesterday someone
created the view with a snippet label *tab *tab and forgot to add an id
Below result of label *tab *tab ..
<asp:Label Text="text" runat="server" />
Should be
<asp:Label Text="text" ID="lblInfo" runat="server" />
Else check the attributes of the page / controls / codebehindfile
make sure the CodeBehindFile attributes are set correctly
see if run at server attribute is properly set on new controls
Like the preview box below that take input from the textarea we are typing now.
The requirement is to retrieve HTML saved in database and preview it on the screen. Should I use label or is there any better control around?
I would use the literal control unless you need to do anything "extra" with the html.
I often use a DIV with a runat="server" attribute declared. That way, I have a container to apply CSS classes to, and I know and can control the markup that is being created.
A Literal will work fine if you don't need a container (or you have a container already on the page).
<div class="css-class">
<asp:Literal runat="server" />
</div>
OR
<div runat="server" class="css-class" />
And as Oded said, watch out for XSS by sanitizing your HTML.
If you simply need to output HTML, use a LiteralControl - you simply set its Text property to the HTML you need.
You may want to think about cleaning up the HTML, if it something that is user input, just in case of XSS attacks hiding in your HTML data.
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.
Haven't tested this, but it might solve your problem : forum post
Otherwise you might use jQuery to solve this. (I think...)
You can try this:
<asp:LoginStatus ID="HeadLoginStatus" runat="server"
LogoutAction="Redirect"
LogoutText="<input type='button' value='Log Out' />"
LogoutPageUrl="~/"/>
The LogoutText attribute contains the definition of a simple button, that you can customize with css and js.
Just use LoginImageUrl or LogoutImageUrl
<asp:LoginStatus runat="server"
LogoutImageUrl="~/App_Themes/Theme1/Images/logout.png"
LoginImageUrl="~/App_Themes/Theme1/Images/login.png" />
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.
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.
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.
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.
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.
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
I know this is an old post but I'll chime in.
Here's a very simple way to make a button out of the LoginStatus control. Set the control CssClass to a bootstrap button and your good to go. Whatever text you have for the login and logout will go into the button.
<asp:LoginStatus ID="LoginStatus1" runat="server" CssClass="btn btn-primary" LogoutPageUrl="yourlogin.aspx" />
http://www.w3schools.com/bootstrap/bootstrap_buttons.asp
Whenever I attempt to set text on the WaterMark Extender (which is on a control) dynamically I get an error saying the that TextBoxWatermarkExtendor missing required watermarktext property value for textboxWatermarkExtender1. The problem is I ONLY get this error some of the time on some computers. It seems to be a loading issue and not browser specific. Does anyone know where I can get some more info about this?
You may not be actually setting the property for watermarktext for the extender.
Take a look # this
<asp:TextBox ID="txtWatermark" runat="server" Width="200px"></asp:TextBox>
<cc1:TextBoxWatermarkExtender ID="txtWatermark_TextBoxWatermarkExtender" runat="server"
Enabled="True" TargetControlID="txtWatermark" WatermarkText="Type Your Search Here">
</cc1:TextBoxWatermarkExtender>
But it is strange that it works only in some computers. Make sure Javascript is turned on in the browsers.
This website has a great tutorial on Watermarked Textboxes + much more :)