This project is read-only.

Anyone Got the Contact Page Working

Topics: Controls
Dec 6, 2009 at 7:27 AM

Even though the Test email works just fine (in the admin settings page), I cannot get the Contact page working.

And as I delve into the code, I can't imagine how it ever could work.

For starters, IsCaptchaValid always returns false no matter what. It's hard coded.

Second, while I see a lot of code associated with showing a captcha, no captcha appears for me.

Finally, the email is not sent unless txtAttachment.HasFile == true. But if I don't allow attachments, I don't think this control is even visible. So how can it ever have a file?

Anyone been able to make sense of this?


Dec 6, 2009 at 7:37 AM

IsCaptchaValid() doesn't always return false.

All that code in btnSend_Click shouldn't run unless a file is attached.  When clicking the Send button, an async callback is made to the server to send the email.  The only time btnSend_Click() should run is if attachments are enabled and the person attaches a file.

When you click the Send button, if a postback to the server occurs, then something is wrong.  I've seen this happen when there's a JavaScript error for example.  You might want to check for any JS errors.  If you have the Compress WebResource.axd option checked in the Advanced Settings section on the Settings tab in the control panel, unchecking that might help.

Dec 6, 2009 at 7:58 AM

Okay, on closer inspection, IsCaptchaValid() doesn't always return false. But it doesn't seem to have anything to do with a captcha.

private bool IsCaptchaValid
      if (ViewState[DateTime.Today.Ticks.ToString()] != null)
         return Request.Form[DateTime.Today.Ticks.ToString()] == ViewState[DateTime.Today.Ticks.ToString()].ToString();
      return false;
As far as btnSend_Click(), it DOES get called for me when I click Send. However, it does happen after the IDE reports a javascript bug. The error is "Microsoft JScript runtime error: Object required." And it highlights the following line in the "dynamic" version of Contact.aspx:

    function beginSendMessage()
      if ($('ctl00_cphBody_txtAttachment').value.length > 0) <<------
        return true;

The Compress WebResource.axd option is unchecked.

I can't make heads or tails of this. Please help...


Dec 6, 2009 at 5:44 PM

Well, after playing with this some more, I see the problem is related to this file-attachment control.

If I check the Enable Attachments option, everything appears to work just fine. If this option is disabled, then it doesn't work at all (no email, no error, no indication whatsoever that anything happened at all) and don't see how it ever could have.

I'd love someone who understands this to chime in but it appears this thread is over.

Dec 6, 2009 at 6:23 PM

It looks like you're using a somewhat old version of BE which had that 'bug' in it.  In the older version like you have, when the file upload control isn't on the page, that JavaScript error occurs.

Here's the contact.aspx page from BE 1.5.

If you use the contact.aspx page from 1.5, you'll probably need to do a search and replace.  You'd want to replace BlogEngine.$ with just $

The main thing to change is in the older contact.aspx, it has code that looks similar to:

if ($('<%=txtAttachment.ClientID %>').value.length > 0)
    return true;

This is basically the same code you posted two posts ago.  If you're not going to use attachments, you can just remove those two lines of code from your existing contact.aspx page, and that should eliminate the JS error.