Ajax WaterMark Extender - c#

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 :)

Related

Asp.net maintainScrollPositionOnPostBack and forms validation fail

I have a very long form that has to be filled out. I have maintainScrollPositionOnPostBack enabled as I have multiple controls that hide/show based on user input.
Since the form is long I'd like for the page to focus and scroll to the first control that caused validation to fail and I have the focus on validation fail option enabled. However, it seems that maintainScrollPositionOnPostBack overrides this (the control does focus but doesn't scroll up to it).
Any ideas for workarounds for this? Everything I've tried so far hasn't worked. It is an asp.net webforms project.
This is a good question and really tricky to get working. But I managed to get one version that you can try and maybe build on.
The MaintainScrollPositionOnPostback="true" -setting sets a series of javascript-events on form submit and window load and these do as you say, "overwrite" the focus set by the validator.
So what I did was add a common css-class to all validators like so:
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" CssClass="error" ErrorMessage="RequiredFieldValidator" SetFocusOnError="true"
EnableClientScript="false" ControlToValidate="TextBox1"></asp:RequiredFieldValidator>
And then I added another eventlistener to window.load (note we need to leave also the one that Asp.Net has added so we cannot do windows.load = function...):
<script>
window.addEventListener("load", function () {
var el = document.getElementsByClassName("error");
if (el.length > 0) {
window.location.hash = "#" + el[0].id;
}
});
</script>
Here you might benefit from jQuery use to be able to support more browsers but addEventListener is pretty well supported.
The script searches for the errormessage and focus on that by it's id with anchor. Javascript has focus-method but it's for form elements so that's why this workaround.
Hope this helps!

AjaxControlToolKit HTMLEditorExtender adding anchor tag as a normal text when a link is added

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)

ASP.NET validator layout for accessibility. Need help with CSS!

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.

Controls on aspx page can't be accessed from code-behind

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 to get raw markup of child controls at runtime

I am trying to create an ASP.net server control for displaying formatted code, using this library: http://www.manoli.net/csharpformat/
Here's the trick: I want be able to express code blocks like this...
<custom:CodeFormatter runat="server">
<asp:Label runat="server" ID="something" Text="my text" />
<asp:Image runat="server" ID="something" ImageUrl="header.jpg" />
</custom:CodeFormatter>
...but not have the inner tags actually execute. I want the Label & Image to be seen by CodeFormatter as raw text, not parsed as real server tags.
So my question is, how to prevent the Label from actually rendering as such? And how to access everything within the custom:CodeFormatter as raw, literal text?
My workaround right now is to encode the <>'s as < and >. I'd love not to do that.
Thanks!
How about extending your control to use ITemplate. Here is a article that explains how to extend a control.
http://www.devx.com/codemag/Article/32182

Categories

Resources