Unfortunately a requiredfieldvalidator doesn’t work with the fckeditor.
The way to do this is to use a custom validator.
<asp:customvalidator runat="server" validateemptytext="true" id="cvIntro" setfocusonerror="true" display="none" errormessage="Please enter an introduction" clientvalidationfunction="ValidateContentText" validationgroup="intro" controltovalidate="fckIntro"></asp:customvalidator>
Important note: you need to set validateemptytext=”true” otherwise it doesn’t fire
Then add the following javascript (note that I’m using jQuery here to reference the validator control)
<script type="text/javascript">
function ValidateContentText(source,args)
{
var controltovalidate = jQuery(source).attr("controltovalidate");
var fckControl = FCKeditorAPI.GetInstance(controltovalidate);
args.IsValid = fckControl.GetXHTML(true) != "";
}
</script>
You might also want to handle the server-side validation too, even though if client-side isn’t working then the fckeditor won’t be working…
Protected Sub cvIntro_ServerValidate(ByVal source As Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs) Handles cvIntro.ServerValidate
Dim myContentPlaceHolder As ContentPlaceHolder
myContentPlaceHolder = CType(Master.FindControl("cphMain"), ContentPlaceHolder)
Dim fckEditorToCheck As FredCK.FCKeditorV2.FCKeditor
fckEditorToCheck = myContentPlaceHolder.FindControl(CType(source, CustomValidator).ControlToValidate)
args.IsValid = Not String.IsNullOrEmpty(fckEditorToCheck.Value)
End Sub
If you are using master pages, you may expect that you can find a control within an tag with the following
me.findcontrol("fckEditor")
But unfortunately that doesn’t work.
You need to make a reference to the place holder the control is in, then find the control within the place holder.
Another gotcha here is that you need to find this control based on the id it has on the master page not the id it has in the page in question.
e.g.
If the tags on the page are
You need to create a reference to the place holder with
Dim myContentPlaceHolder As ContentPlaceHolder
myContentPlaceHolder = CType(Master.FindControl("cphMain"), ContentPlaceHolder)
and not
Dim myContentPlaceHolder As ContentPlaceHolder
myContentPlaceHolder = CType(Master.FindControl("Content2"), ContentPlaceHolder)
Hope that saves someone some time!
I’ve looked for unzipping functionality for .net a couple of times over the years and never found a totally satifactory solution.
In a recent project I had to grab an attachment from a POP box and then unzip the attachment.
I found an unzipping product called 7zip, it’s open source and there’s a command line version. See their downloads page for the commandline version - http://www.7-zip.org/download.html
Once you have this exe on your server you can easily unzip a file using the following code:
dim pathToZip as string = "c:\some\folder\file.zip"
Dim p As Process = Process.Start("C:\Program Files\7Zip\7za.exe", "e " & pathToZip & " -oc:\")
p.WaitForExit()
Obviously you are not limited to just unzipping, you can do anything the command line version does: zip, password protect a zip file, list the contents, etc
The outputcache page directive is very handy - and I tend to use this where appropriate on my usercontrols (.ascx)
You can optionally vary by querystring parameters.
Something that’s missing from the default options is to vary based on the actual url of the page. I was building a site where a random testimonial was pulled from the database and displayed in a small panel. I wanted this to stay constant on each particular url.
Here’s how to do it…
Add this to your global.asax
Public Overrides Function GetVaryByCustomString(ByVal context As HttpContext, ByVal custom As String) As String
Select Case custom.ToLower
Case "pageurl"
Return Request.FilePath.ToLower
Case Else
' Return String.Empty
Return MyBase.GetVaryByCustomString(context, custom)
End Select
End Function
Then on your ascx file add the following to the top
<%@ OutputCache Duration="60" Shared="true" VaryByParam="None" VaryByCustom="pageurl" %>