Веб-форма не загружается и не отображается

#c# #asp.net #webforms

#c# #asp.net #веб-формы

Вопрос:

Прошло пару лет с тех пор, как я в последний раз вносил обновления в ASP.NET веб-сайт 4.5 web forms, и мне нужна небольшая помощь.

По какой-то причине всякий раз, когда я пытаюсь получить доступ к странице, вместо этого я отправляюсь на страницу ошибки, и я понятия не имею, почему. Если бы вы могли указать на что-то, чего мне не хватает, это было бы оценено.

Моя веб-форма:

 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="incident.aspx.cs" Inherits="incident" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <asp:PlaceHolder runat="server">
        <%: System.Web.Optimization.Scripts.Render("~/Bundles/jqScript") %>
        <%: System.Web.Optimization.Scripts.Render("~/Bundles/BootstrapJs") %>
        <%: System.Web.Optimization.Styles.Render("~/Bundles/BootstrapCSS") %>
        <%: System.Web.Optimization.Styles.Render("~/Bundles/MainStyle") %>

    </asp:PlaceHolder>
    
</head>
<body>
    <form id="form1" runat="server">
    <div class="container-fluid">
    <div class="row">
        <div class="col">
            <label>Reporting Persons Name: </label>                    
                    <asp:TextBox ID="txtReportersName" runat="server" CssClass="form-control" TextMode="SingleLine"></asp:TextBox><br />

            <label>Reporting Persons Contact Number: </label>                    
                    <asp:TextBox ID="txtReportesPhone" runat="server" CssClass="form-control" TextMode="Phone"></asp:TextBox><br />

            <label>Reporting Persons Email Address: </label>                    
                    <asp:TextBox ID="txtReportesEmail" runat="server" CssClass="form-control" TextMode="Email"></asp:TextBox><br />

            <label>Date of Incident: </label>                    
            <asp:RequiredFieldValidator ID="rqDateIncident" runat="server" ErrorMessage="*" ForeColor="Red" Display="Dynamic" ControlToValidate="txtDateIncident" ValidationGroup="incident"></asp:RequiredFieldValidator>
                    <asp:TextBox ID="txtDateIncident" runat="server" CssClass="form-control" TextMode="Date"></asp:TextBox><br />

            <label>Time of Incident: </label>                    
            <asp:RequiredFieldValidator ID="rqTimeIncident" runat="server" ErrorMessage="*" ForeColor="Red" Display="Dynamic" ControlToValidate="txtTimeIncident" ValidationGroup="incident"></asp:RequiredFieldValidator>
                    <asp:TextBox ID="txtTimeInciden" runat="server" CssClass="form-control" TextMode="Time"></asp:TextBox><br />

            <label>Name/s of Person/s involved or description:</label>                    
            <asp:RequiredFieldValidator ID="rqPerson" runat="server" ErrorMessage="*" ForeColor="Red" Display="Dynamic" ControlToValidate="txtPerson" ValidationGroup="incident"></asp:RequiredFieldValidator>
                    <asp:TextBox ID="txtPerson" runat="server" CssClass="form-control" TextMode="SingleLine"></asp:TextBox><br />

            <label>Associated Team: </label>                    
            <asp:RequiredFieldValidator ID="rqTeam" runat="server" ControlToValidate="drpTeams" InitialValue="0" ErrorMessage="*" Display="Dynamic" ForeColor="Red" ValidationGroup="hood"></asp:RequiredFieldValidator>
                    <asp:DropDownList ID="drpTeams" runat="server" CssClass="form-control" AppendDataBoundItems="true">
                        <asp:ListItem Text="Please select team" Value="0"></asp:ListItem>
                        <asp:ListItem Text="Mini-Crows" Value="Mini-Crows"></asp:ListItem>
                        <asp:ListItem Text="Inclusive" Value="Inclusive"></asp:ListItem>
                        <asp:ListItem Text="Wildcats" Value="Wildcats"></asp:ListItem>
                    </asp:DropDownList><br />

            <label>Match Day Delegate: </label>
                    <asp:TextBox ID="txtDelegate" runat="server" CssClass="form-control" TextMode="SingleLine"></asp:TextBox><br />

            <label>Location of Incident: </label>                    
            <asp:RequiredFieldValidator ID="rqLocation" runat="server" ErrorMessage="*" ForeColor="Red" Display="Dynamic" ControlToValidate="txtLocation" ValidationGroup="incident"></asp:RequiredFieldValidator>
                    <asp:TextBox ID="txtLocation" runat="server" CssClass="form-control" TextMode="SingleLine"></asp:TextBox><br />

            <label>Name/s of Witness/es and contact information: </label>
                    <asp:TextBox ID="txtWitness" runat="server" CssClass="form-control" TextMode="MultiLine"></asp:TextBox><br />

            <label>Summary of the Incident – please give as much detail as possible: </label>
            <asp:RequiredFieldValidator ID="rqSummary" runat="server" ErrorMessage="*" ForeColor="Red" Display="Dynamic" ControlToValidate="txtSummary" ValidationGroup="incident"></asp:RequiredFieldValidator>
                    <asp:TextBox ID="txtSummary" runat="server" CssClass="form-control" TextMode="MultiLine" Rows="4"></asp:TextBox><br />


            <asp:Button ID="btnReportIncident" runat="server" OnClick="btnReportIncident_Click" Text="Report Incident" CssClass="btn btn-success" ValidationGroup="incident" />
        </div>
    </div>
    </div>
    </form>
</body>
</html>
  

И мой код за:

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class incident : System.Web.UI.Page
{
    private TeamsBLL teamLogic = new TeamsBLL();
    private UserBLL userlogic = new UserBLL();
    protected void Page_Load(object sender, EventArgs e)
    {
        GetTeams();
    }
    protected void GetTeams()
    {
        var boysmixedDS = teamLogic.GetAllTeams();
        if (boysmixedDS != null)
        {
            if (boysmixedDS.Rows.Count > 0)
            {
                boysmixedDS.DefaultView.Sort = "AgeGroup ASC";
                drpTeams.DataSource = boysmixedDS;
                drpTeams.DataTextField = "TeamName";
                drpTeams.DataValueField = "TeamId";
                drpTeams.DataBind();
            }
        }
        boysmixedDS.Dispose();
    }



    protected void btnReportIncident_Click(object sender, EventArgs e)
    {
        //string sendTo = @"rtyfcautosend@roystontownyouthfc.co.uk";
        string sendTo = @"michael@griffithswebdesign.com";
        string subject = "Incident Report Form - Royston Town Youth";        
        string team = drpTeams.SelectedItem.Text;       
        string repName = "Not Supplied";
        if(txtReportersName.Text != "")
        {
            repName = txtReportersName.Text;
        }
        string repPhone = "Not Supplied";
        if(txtReportesPhone.Text != "")
        {
            repPhone = txtReportesPhone.Text;
        }
        string repEmail = "Not Supplied"; 
        if(txtReportesEmail.Text != "")
        {
            repEmail = txtReportesEmail.Text;
        }
        string dateOfIncident = txtDateIncident.Text;
        string timeOfIncident = txtTimeInciden.Text;
        string namesInvolved = txtPerson.Text;
        string associatedTeam = drpTeams.SelectedItem.Text;
        string matchDayDel = "Not Supplied";
        if(txtDelegate.Text != "")
        {
            matchDayDel = txtDelegate.Text;
        }
        string location = txtLocation.Text;
        string witness = "Not Supplied";
        if(txtWitness.Text != "")
        {
            witness = txtWitness.Text;
        }

        string incidentSummary = txtSummary.Text;

        string bod;

        string aklertscript = "<script type="text/javascript">alert('Thank you. Our Welfare Team who will endeavour to investigate within 7 days');</script>";
        string erScript = "<script type="text/javascript">alert('Sorry, something went wrong. Please try again later.');</script>";
        
        
            bod = "<div style='color:#000000;'><h1>"   subject   "</h1> <p><strong>Reporting Persons Name: </strong>"   repName   "</p><p><strong>Reporting Persons Contact Number:</strong> "   repPhone   "</p><p><strong>Reporting Persons Email Address: </strong> ";
            bod  = repEmail   "</p><p><strong>Date of Incident: </strong>"   dateOfIncident   "</p><p><strong>Time of Incident: </strong>"   timeOfIncident   "</p><p><strong>Name/s of Person/s involved or description: </strong>"   namesInvolved   "</p><p><strong>Team: </strong>";
            bod  = associatedTeam   "</p><p><strong>Match Day Delegate: </strong>"   matchDayDel   "</p><p><strong>Location of Incident: </strong>"  location   "</p><p><strong>Name/s of Witness/es and contact information: </strong>"   witness   "</p><p><strong>Summary of the Incident: </strong>"   incidentSummary   "</p></div>";
            try
            {
                userlogic.SendEmailMessage(sendTo, subject, bod);
                txtReportersName.Text = "";
            txtReportesPhone.Text = "";
            txtReportesEmail.Text = "";
            txtDateIncident.Text = "";
            txtTimeInciden.Text = "";
            txtPerson.Text = "";
            txtDelegate.Text = "";
            txtLocation.Text = "";
            txtWitness.Text = "";
            txtSummary.Text = "";
                drpTeams.SelectedIndex = 0;
                ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", aklertscript);

            }
            catch (Exception)
            {
                ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", erScript);
            }

        
    }
}
  

Вы действительно поможете мне выбраться из затруднительного положения с этим, поэтому я очень ценю ваше понимание.

Комментарии:

1. что говорится на странице ошибки?

2. Я не уверен, он просто перенаправляет на страницу ошибки

3. Теперь я разобрался с этим. После небольшой возни я вспомнил, как заставить ошибки отображаться lol. Это была опечатка, враг всех программистов. Все равно спасибо @Hoshani за вашу помощь.

4. добро пожаловать