在服务器上发布时不会调用后面的用户控制代码

时间:2015-02-03 18:42:32

标签: c# asp.net user-controls telerik

我有一个简单的用户控件,基本上是一个联系表单,由三个文本框,1个按钮和1个标签组成。我也在使用Telerik RadAjaxLoadingPanel和RadAjaxPanel。下面给出了用户控件的标记,

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

在我背后的代码中,我只是将文本框中的信息发送到电子邮件地址。单击提交按钮时事件的代码如下,

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 ! ";
        }

    }

用户控件就像这样调用,

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

在页面顶部,

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

现在这一切都很简单,在我的测试机器上工作得很好。当我在服务器中发布它时,然后显示加载图像,但不会触发后面的代码。我试图在用户控件的Page_Load事件上的标签中设置虚拟文本,但即使该测试也不会显示在实时服务器上的用户控件上。我每次在本地提交时都会收到电子邮件。

我的问题是,当用户控件在实时服务器上发布并且其他人遇到此类问题时,为什么不调用后面的代码?

编辑:(从控制台找到的错误)

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

第二个错误:

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

1 个答案:

答案 0 :(得分:2)

如果你在ajax面板中有某些东西,并且由于某种原因开始不起作用,则可能是你错过了一个javascript错误,一个未加载的文件,一个你没看到的异常。

在这种情况下,只需删除ajax面板以找到代码上的错误,和/或检查浏览器上的javascript控制台错误。

从您的评论中听到,如果用户未经过身份验证,某些文件夹上的某些javascript文件由于安全性而无法加载,那么您会遇到一些javascript错误,导致代码无法正常运行。