0

I have a simple user control which is basically a contact form and consists of three text boxes, 1 button and 1 label. I am also using Telerik RadAjaxLoadingPanel and RadAjaxPanel. The markup of the user control is given below,

<telerik:RadAjaxLoadingPanel ID="RALP_ContactForm" runat="server" Transparency="5">
    <div class="border" style="display: table; height: 240px; width: 240px; #position: relative;
        overflow: hidden; background-color:White">
        <div class="border" style="#position: absolute; #top: 50%; display: table-cell; text-align: center;
            vertical-align: middle;">
            <div class="border" style="width: 100%; #position: relative; #top: -50%">
                <img src="images/cf_animation.GIF" alt="Processing Request..." />
            </div>
        </div>
        </div>
</telerik:RadAjaxLoadingPanel>

<telerik:RadAjaxPanel ID="upContactForm" runat="server">
    <div id="form-main">
        <div id="form-div">
            <p class="name">
                <asp:TextBox ID="txtContactName" ValidationGroup="ContactForm" CausesValidation="true"
                    runat="server" name="name" CssClass="validate[required,custom[onlyLetter],length[0,100]] feedback-input"
                    ClientIDMode="Static" placeholder="Name"></asp:TextBox>
                <asp:CustomValidator ID="customValidator" runat="server" ValidationGroup="ContactForm"
                    ControlToValidate="txtContactName" Display="Dynamic" ClientValidationFunction="ValidateContactName"
                    ErrorMessage="" ValidateEmptyText="true"></asp:CustomValidator>
            </p>
            <p class="email">
                <asp:TextBox ID="txtContactEmail" ValidationGroup="ContactForm" CausesValidation="true"
                    runat="server" name="email" CssClass="validate[required,custom[onlyLetter],length[0,100]] feedback-input"
                    ClientIDMode="Static" placeholder="Email"></asp:TextBox>
                <asp:CustomValidator ID="customValidator1" runat="server" ValidationGroup="ContactForm"
                    ControlToValidate="txtContactEmail" Display="Dynamic" ClientValidationFunction="ValidateContactEmail"
                    ErrorMessage="" ValidateEmptyText="true"></asp:CustomValidator>
            </p>
            <p class="text">
                <asp:TextBox ID="txtContactComment" ValidationGroup="ContactForm" CausesValidation="true"
                    TextMode="MultiLine" runat="server" name="text" ClientIDMode="Static" CssClass="validate[required,custom[onlyLetter],length[0,100]] feedback-input"
                    placeholder="Comment"></asp:TextBox>
                <asp:CustomValidator ID="customValidator2" runat="server" ValidationGroup="ContactForm"
                    ControlToValidate="txtContactComment" Display="Dynamic" ClientValidationFunction="ValidateContactComment"
                    ErrorMessage="" ValidateEmptyText="true"></asp:CustomValidator>
            </p>
            <p><asp:Label ID="lblMessage" runat="server" Visible="false"></asp:Label></p>
            <div class="submit">
                <asp:Button ID="btnSubmitContactForm" Width="100%" runat="server" ValidationGroup="ContactForm"
                    Text="SEND" CssClass="btn-flat gr btn-submit-reg" OnClick="btnSubmitContactForm_Click" />
            </div>
        </div>
    </div>

On the code behind I am just sending the information from the textboxes to an email address. The code for the event when the submit button is clicked is as follow,

protected void btnSubmitContactForm_Click(object sender, EventArgs e)
    {
        try
        {                
            string AppPath = Request.PhysicalApplicationPath;
            StreamReader sr = new StreamReader(AppPath + "EmailTemplates/UserFeedback.htm");

            string MailBody = sr.ReadToEnd();
            MailBody = MailBody.Replace("<%Name%>", txtContactName.Text.Trim());
            MailBody = MailBody.Replace("<%Email%>", txtContactEmail.Text.Trim());
            MailBody = MailBody.Replace("<%Comments%>", txtContactComment.Text.Trim());

            // Close the StreamReader after reading text from it
            sr.Close();

            MailMessage message = new MailMessage(
                                   "sender@mymail.com",
                                   "receiver@mymail.com",
                                   "Feedback",
                                   MailBody);

            message.IsBodyHtml = true;

            SmtpClient smtp = new SmtpClient();
            smtp.Host = "mail.myserver.com";
            smtp.Port = 25;
            smtp.EnableSsl = false;
            smtp.Credentials = new NetworkCredential("MyUserName", "MyPassword");

            try
            {
                smtp.Send(message);
            }
            catch
            {

            }

            txtContactComment.Text = "";
            txtContactEmail.Text = "";
            txtContactName.Text = "";

            lblMessage.Visible = true;
            lblMessage.ForeColor = System.Drawing.Color.Green;
            lblMessage.Text = "Feedback sent successfully!";

        }
        catch
        {
            lblMessage.Visible = true;
            lblMessage.ForeColor = System.Drawing.Color.Red;
            lblMessage.Text = "Error sending feedback ! ";
        }

    }

The User control is called like this,

<uc1:FooterContactForm ID="FooterContactForm" runat="server"></uc1:FooterContactForm>

And at the top of the page,

<%@ Register Src="ContactForm.ascx" TagName="FooterContactForm" TagPrefix="uc1" %>

Now all this is very simple and works just fine on my test machine. When I publish this in the server then loading image is displayed but code behind is not fired. I have tried to set the dummy text in the label on Page_Load event of the user control but even that test is not displayed on the user control on live server. I am receiving email every time when I submit this locally.

My question is that why the code behind is not called when the user control is published on the live server and is someone else has experienced such issue?

Edit: (Errors found from console)

POST http://test.mywebsite.com/ 500 (Internal Server Error)
Telerik.Web.UI.WebResource.axd?_TSM_HiddenField_=RadScriptManager1_TSM&compress=1&_TSM_CombinedScri…:6 
Sys.Net.XMLHttpExecutor.executeRequest
Telerik.Web.UI.WebResource.axd?_TSM_HiddenField_=RadScriptManager1_TSM&compress=1&_TSM_CombinedScri…:6 
Sys.Net._WebRequestManager.executeRequest
Telerik.Web.UI.WebResource.axd?_TSM_HiddenField_=RadScriptManager1_TSM&compress=1&_TSM_CombinedScri…:6 
Sys.Net.WebRequest.invoke
Telerik.Web.UI.WebResource.axd?_TSM_HiddenField_=RadScriptManager1_TSM&compress=1&_TSM_CombinedScri…:15 
Sys.WebForms.PageRequestManager._onFormSubmit
Telerik.Web.UI.WebResource.axd?_TSM_HiddenField_=RadScriptManager1_TSM&compress=1&_TSM_CombinedScri…:15 
Sys.WebForms.PageRequestManager._doPostBackTelerik.Web.UI.WebResource.axd?_TSM_HiddenField_=RadScriptManager1_TSM&compress=1&_TSM_CombinedScri…:15 
Sys.WebForms.PageRequestManager._doPostBackWithOptions
Telerik.Web.UI.WebResource.axd?_TSM_HiddenField_=RadScriptManager1_TSM&compress=1&_TSM_CombinedScri…:6 
(anonymous function)(index):800 
onclick

Second error:

Uncaught Sys.WebForms.PageRequestManagerServerErrorException:    
Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occurred while processing the request on the server. The status code returned from the server was: 500
Telerik.Web.UI.WebResource.axd?_TSM_HiddenField_=RadScriptManager1_TSM&compress=1&_TSM_CombinedScri…:6 Error.create
Telerik.Web.UI.WebResource.axd?_TSM_HiddenField_=RadScriptManager1_TSM&compress=1&_TSM_CombinedScri…:15 
Sys.WebForms.PageRequestManager._createPageRequestManagerServerError
Telerik.Web.UI.WebResource.axd?_TSM_HiddenField_=RadScriptManager1_TSM&compress=1&_TSM_CombinedScri…:15 
Sys.WebForms.PageRequestManager._onFormSubmitCompleted
Telerik.Web.UI.WebResource.axd?_TSM_HiddenField_=RadScriptManager1_TSM&compress=1&_TSM_CombinedScri…:6 (anonymous function)
Telerik.Web.UI.WebResource.axd?_TSM_HiddenField_=RadScriptManager1_TSM&compress=1&_TSM_CombinedScri…:6 (anonymous function)
Telerik.Web.UI.WebResource.axd?_TSM_HiddenField_=RadScriptManager1_TSM&compress=1&_TSM_CombinedScri…:6 
Sys.Net.WebRequest.completed
Telerik.Web.UI.WebResource.axd?_TSM_HiddenField_=RadScriptManager1_TSM&compress=1&_TSM_CombinedScri…:6 _onReadyStateChange
Adnan Yaseen
  • 833
  • 1
  • 15
  • 44
  • 1
    You have that inside ajax panel, so probably some javascript errors cut it from correctly run. Try to remove the ajax panel to see if you have errors, also open your javascript browser console to locate the errors. – Aristos Feb 03 '15 at 18:51
  • @Aristos I have updated my question. Yes you were right, I have found that in console two errors are displayed. They are not javascript error? Also I am curious that why these errors are not produced on the local machine? – Adnan Yaseen Feb 03 '15 at 19:11
  • Yes removing the Ajax panel has solved the issue. – Adnan Yaseen Feb 03 '15 at 19:35
  • @Aristos, If you give this as an answer then will accept it as an answer and can vote. – Adnan Yaseen Feb 03 '15 at 19:36
  • Ok it is interesting but I have found out that the error only occurs when the user is not authenticated. When the user is authenticated then it works and doesn't give any error. Authentication is only enabled for specific folder and rest of the website can be used without logged in. – Adnan Yaseen Feb 03 '15 at 19:49

1 Answers1

2

When you have something inside an ajax panel, and for some reason starts to not work, then is probably a javascript error that you miss, a file that is not loaded, an exception that you did not see.

In this cases just remove the ajax panel to locate the error on the code, and/or check the javascript console error on the browser.

From your comments sounds that if the user is not authenticated, some javascript files on some folder fail to load because of the security and then you have some javascript errors that not let your code run correctly.

Aristos
  • 66,005
  • 16
  • 114
  • 150
  • Well I am accepting you reply as an answer as it helped me investigating a lot but this issue is not related to any javascript or any other programming error. I experienced this error earlier also but that was another issue. When the site domain is www.mydomain.com then this error is displayed. When the site domain is www.mydomain.com/Default.aspx then the contact form works just fine without any issue. So it is not the issue of any error rather issue of the domain. How strange is it? Can any one with url rewriting experince shed light on this? – Adnan Yaseen Feb 04 '15 at 19:51
  • @AdnanYaseen Yes you may need to set the cookie name in the web.config, both on cookie and authenticate. – Aristos Feb 04 '15 at 19:58
  • @AdnanYaseen Look at this answer (focus on `domain=`) : http://stackoverflow.com/questions/12506532/session-would-not-retain-values-and-always-return-null/12506833#12506833 – Aristos Feb 04 '15 at 19:59