简体   繁体   中英

User Control code behind is not called when published on server

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM