I'm wondering if anyone can help me with a problem I've been scratching my head with lately. Its about accessible error messages on forms, and I've spent so long researching this without finding anything useful, or any related examples.
I've uploaded a mock page of the layout problem here. I've just made it using html in the same way that asp.net will render it. I can't upload an image because I have to build up points on this forum first so I've just linked to here for an example i've built in the same style http://hbtester.chickenkiller.com/ValidationLayoutTest.htm .
On the site I work on previously all our error messages were like the bottom red error message. A seperate with an asp.net validator in that is rendered to a . But as part of an accessibility audit we undertook I had to move all the validators into the label that is associated with each textbox/form control (after much discussion). The code looks like this
<tr>
<td>
<asp:Label ID="parentLabel" AssociatedControlID="input" runat="server">
<asp:Label ID="childLabel" AssociatedControlID="input" runat="server" Text="Enter number here" />
<asp:CustomValidator ID="errorValidator" runat="server" CssClass="error" ControlToValidate="sharesWithDrp"
ErrorMessage="Error message"></asp:CustomValidator>
</asp:Label>
</td>
<td>
<asp:TextBox ID="input" runat="server"></asp:TextBox>
</td>
</tr>
(I've checked it with accessiblity validators and it passes, and a screenreader reads out the error message when in forms mode going to the offending field)
As you can see, the bottom message in the old style looks much better than the top one, and I would like it look like this. Does anyone know if this would be possible? Spent loads of time messing around with CSS with no luck.
has anyone any experience of doing this stuff in ASP.NET? It seems like it should be quite a common thing but I can't find anything. please let me know if i'm gone about this completely the wrong way!
Cheers,
Buswell
The only difference i see between the two error messages on that site is that the bottom one spans across two columns in your table. If you need to have the error message box nested inside the label, the only solution i can think of is moving away from your table layout.
You can check out some alternative methods here; http://www.websiteoptimization.com/speed/tweak/forms/
When you are not constrained to table-cells it should be a small task to position error messages however you like.
Related
I am unable to write a nice title to this topic because my problem is a little weird. I am using AjaxControlToolkit HTMLEditorExtender in my website to send HTML formatted emails. Every other feature like bold, italic, underline etc. are working fine but when I add a link it shows the HTML code of it as follows:
As you can see BOLD is working but the anchor tag is appearing in HTML code format.
Code for extender and the textbox:
<asp:TextBox ID="TextBox2" runat="server" Height="376px"
TextMode="MultiLine" Width="795px"></asp:TextBox>
<asp2:HtmlEditorExtender ID="TextBox2_HtmlEditorExtender"
runat="server" Enabled="True" TargetControlID="TextBox2">
</asp2:HtmlEditorExtender>
Can any one please tell me why this is happening? Is this some bug with the extender?
Considering I do not have enough reputation for commenting on the post, I will ask a followup question here. Is there any way we could see the text you are getting on your C# backend? This is a possible source for the issue if the string has some weird formatting.
Plus email clients are not meant to be browsers and there is a possibility that the email client will not render the html correctly.
Is that image a screen shot of the editor itself? I created my own test project using your same code.
Also, how did you create the link? I typed some text highlighted the text and clicked on the 'create link' icon and from there I typed in the URL. It created the link as expected.
The only difference is that I didn't bother implementing a sanitizer, which it appears you did. I would try disabling the sanitizer (just for testing purposes) and see if that's where your problem lies.
Try this it should solve your issue-
txtEmialMsg.Text=Server.HtmlDecode(ActualStringFromExtender.ToString());
Or if you are getting (A href) text then you need to use following when sending emails
Server.UrlDecode(link)
Alright, I have an embarrassingly simple question that hopefully has an embarrassingly simple answer. I am trying to get an asp:ImageButton to display an alert message that contains variables from my codebehind. Here's the overly simplified version of the code:
public string AlertMe
{
get
{
return "alert('hi');";
}
}
Now when I try and access it this way:
<asp:ImageButton ID="btn" runat="server" ImageUrl="/Images/img.ico" OnClientClick='<%=AlertMe%>'/>
I see a postback, but no alert message, as if it can't access my property at all. Meanwhile, these 2 lines:
<%=AlertMe%><br />
<a onclick="<%=AlertMe%>">click this</a>
both work fine and dandy. (The first displays the code for the javascript alert, and the second fires the alert with no issues.)
So my big question is: why does the OnClientClick event for an asp control fail to register the alert? Is there an obvious flaw I'm missing, or do I really need to register the entire event from code-behind?
You can't use the <%= ... %> syntax to set attributes of a Server Control. To set dynamic attributes on Server Controls, you have to set it in code.
this.btn.OnClientClick = this.AlertMe;
This is because <%= ... %> is a shortcut for Response.Write(). So, it isn't called until after the aspx has been parsed, evaluated, and rendering has begun. By then it's too late.
As an alternative to setting the value in the code behind, you could use this quasi-declarative technique:
<asp:ImageButton ID="btn" runat="server" ImageUrl="/Images/img.ico" />
<%
btn.OnClientClick = <%=AlertMe%>;
%>
There are other ways to get around it. This answer to a similar question discusses several approaches you can take. I can't find any "official" reference (eg, msdn) that mentions this specifically, but I didn't look that hard. Here are a couple of blog posts that discuss the issue as well:
Blog post by Jim Black: Server tags cannot contain <% ... %> constructs
Blog post at weblogs.asp.net: Use ExpressionBuilder To Avoid “Server tags cannot contain <% … %> constructs”
Or google it with bing for more fun reading.
For anyone else encountering this issue, I ran across this blog from way back when:
http://weblogs.asp.net/infinitiesloop/archive/2006/08/09/The-CodeExpressionBuilder.aspx
I found the sections about Expression Builders and ViewState concerns to be particularly informative.
I think its a quoting problem. Try
OnClientClick="<%=AlertMe%>"
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
How do I disable an if the user is not logged in?
<asp:MenuItem NavigateUrl="~/Customizations.aspx" Text="Customizations" Enabled="<%# Page.User.Identity.IsAuthenticated %>" />
Doesn't work, even if I specify Page.DataBind() in the Page_Load method.
<% if (HttpContext.User.Identity.IsAuthenticated) { %>
<asp:MenuItem NavigateUrl="~/Customizations.aspx" Text="Customizations" />
<% } %>
Gives the error: Parser Error Message: Code blocks are not supported in this context.
I tried adding an ID attribute, and it gives an error saying it isn't a supported attribute.
Any ideas?
While trying to make webforms like winforms, Microsoft came up short and hasn't faithfully represented a lot of the properties in the winforms MenuItem object, specifically the Visible property. They've also sealed the class barring the ability to work around this oversight through polymorphism.
It would be brilliant to be able to do something like this:
<asp:MenuItem NavigateUrl="~/Customizations.aspx" Text="Customizations" Visible="<%# HttpContext.User.Identity.IsAuthenticated %>/>
You're unfortunately probably going to have to resort to either building or modifying your list in the code-behind.
I would say default the ones that may be in question for users by setting Visible="false" and for the ones that should be visible, set Visible=true in code... there isn't any good inline support for this in web forms.
HTH
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 :)