【问题标题】:A page can have only one server-side Form tag. error一个页面只能有一个服务器端 Form 标签。错误
【发布时间】:2020-05-26 12:19:35
【问题描述】:

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

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>       
</head>
<body>
<form id="license" runat="server">       
        <asp:Image ID="logo" runat="server" ImageAlign="Middle" Width="100px" Height="100px" CssClass="img" /><br />       
    <table style="width: 100%; height: 800px">
        <tr>                
            <td colspan="2" align="center">
                <asp:Image ID="logo" Width="100px" Height="100px" runat="server" ImageUrl="~/Image/kar_logo4.jpg" ImageAlign="Middle" />
            </td>

        </tr>
        <tr style="height:10px!important;">
            <%-- <td class="auto-style2"></td>--%>
            <td colspan="2" align="center">
                <span style="font-size: 25px">License</span>
            </td>
        </tr>
        <tr style="height:10px!important;">
            <td class="auto-style2"></td>
            <td style="border: 0px; margin: auto;  width: 40%; text-align: left">
                <br />

                  Registration No -
                        <asp:Label ID="Reg_no" runat="server"></asp:Label>
                <br />
                License No -
                        <asp:Label ID="lbllice_no" runat="server"></asp:Label><br />
                Valid From -
                        <asp:Label ID="isueDate" runat="server"></asp:Label><br />
                Valid upto -
                        <asp:Label ID="validDate" runat="server"></asp:Label>

            </td>
        </tr>
        <tr>
            <td colspan="2" align="center">
                <b>FORM 'A2' </b>
                <br />
                ACKNOWLEDGEMENT<br />
                (<asp:Label ID="License_type" runat="server" Text="Label"></asp:Label>
                )<br />
                [See Clause 8 (3)]<br />
            </td>
        </tr>
    </table>
    <br />
    <div class="row">
        <div class="col-md-12">
            <table class="table">
                <tr>
                    <td colspan="2" style="padding-top: 0px; height: 30%">
                        <p>
                            Received from
                                           <asp:Label ID="lblmrs" runat="server"></asp:Label>
                            &nbsp;<asp:Label ID="lblname" runat="server"></asp:Label>
                            ,
                                        <asp:Label ID="lblpname" runat="server" Text="Label"></asp:Label>
                            , a complete Memorandum of Intimation along with Form O, fee of Rs.
                                                <asp:Label ID="lblfee" runat="server"></asp:Label>
                            /- bearing SBI(Govt.),
                                                <asp:Label ID="lblbranch" runat="server"></asp:Label>
                            , Dated
                                                <asp:Label ID="lblpaiddate" runat="server"></asp:Label>
                            .
                                                <br />
                        </p>
                        <br />
                        <p>This acknowledgement shall be deemed to be the letter of authorization entitling the applicant to carry on the business as applied for, for a period of 5 years from the date of issue of this Memo of acknowledgement unless suspended or revoked by the competent authority.</p>
                        <br />
                        <p>

                                        <asp:Label ID="lblrespon" runat="server"></asp:Label>
                            ,
                                            <asp:Label ID="lblradres" runat="server"></asp:Label>
                            , Email-id:
                                                <asp:Label ID="lblemail" runat="server"></asp:Label>
                            , Mob. No:
                                                <asp:Label ID="lblmob" runat="server"></asp:Label>
                            &nbsp;is the responsible officer as per clause 24 of FCO, 1985.
                        </p>
                        <br />
                        <br />
                        *Enclosed details of Fertilizers in Annexure.
                    </td>
                </tr>

            </table>
     </form>
  </body>
  </html>

   protected void export_click(object sender, EventArgs e)
    {
        using (StringWriter sw = new StringWriter())
        {
            using (HtmlTextWriter hw = new HtmlTextWriter(sw))
            {
                string strid = Utilities.Decrypt(Request.QueryString["lbid1122"].ToString().Trim().Replace(" ", "+"), ConfigurationManager.AppSettings["AadharEncKey"]);
                string appPath = HttpContext.Current.Request.ApplicationPath;
                logo.ImageUrl = Server.MapPath(".") + "\\Image\\kar_logo4.jpg";                   
                string path = Server.MapPath(appPath + "eSign/eSignfiles/" + strid + ".pdf");
                this.Page.RenderControl(hw);
                dynamic output = new FileStream(path, FileMode.Create);
                StringReader sr = new StringReader(sw.ToString());
                Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
                PdfWriter writer = PdfWriter.GetInstance(pdfDoc, output);
                pdfDoc.Open();                  
                XMLWorkerHelper.GetInstance().ParseXHtml(writer, pdfDoc, sr);                   
                pdfDoc.Close();
                Response.ContentType = "application/pdf";
                Response.AddHeader("content-disposition", "attachment;filename=" + strid + ".pdf");
                Response.Cache.SetCacheability(HttpCacheability.NoCache);
             }
        }
    }

页面仅显示一个服务器端表单标签错误,尽管我只有一个表单标签,但我也没有使用任何母版页。请帮助我这可能是什么问题。 我已经发布了页面的完整代码,请查看这个我没有在代码中的任何地方使用表单标签。

一件事是它在本地工作完全正常,但当推送到服务器时,我们收到此错误

我正在使用 XMLWorkerHelper 生成 PDF 是因为这个错误吗?

更新页面加载代码

protected void Page_Load(object sender, EventArgs e)
    {       
            pageName = Path.GetFileName(Request.Path);
            uid = Session["UserID"] != null ? Convert.ToString(Session["UserID"].ToString().Trim()) : "";
        if (IsPostBack == false)
        {
            if ((Session["RoleCode"].ToString() == "11") || (Session["RoleCode"].ToString() == "2") || (Session["RoleCode"].ToString() == "5") || (Session["RoleCode"].ToString() == "8") || (Session["RoleCode"].ToString() == "4"))
            {
                uploading();
                gridstoragebind();
                export_click(this, null);
            }
            else
            {
                Session.Clear();
                Response.Redirect("~/Login.aspx");
            }
        }

UPDATE Uploading() 方法

 private void uploading()
   {
    try
    {
        if (con.State == ConnectionState.Closed)
            con.Open();
        string strid = Utilities.Decrypt(Request.QueryString["lbid1122"].ToString().Trim().Replace(" ", "+"), ConfigurationManager.AppSettings["AadharEncKey"]);            

        string query = "select LI.RegNo,af.App_Name,af.Photo,d.DName,t.TName,ur.Gender,af.Sales_Adress,dt.Dealer_Region,LI.License_No,LI.Responsible_person,LI.Generated_Date,LI.Respo_Adres,LI.Respo_adhar,LI.Respo_email,LI.Respo_Mob, convert(varchar(100),LI.Issue_Date,103) Issue_Date,convert(varchar(100),LI.Valid_Date,103) Valid_Date,d.DName,t.TName,LI.Approved_by,FP.AmountPaid,FP.BranchName,convert(varchar(100),FP.PaidDate,103) as PaidDate from FL_License_issued as LI " +
                        "join FL_Form_A1 as af on af.Reg_No=LI.RegNo " +
                        "join User_Registration as ur on af.user_id = ur.user_id " +
                        "join FL_mst_Applying_category as dt on LI.Dealer_Type=dt.Dealer_Code " +
                        "left join FeePayment as FP on LI.RegNo=FP.RegNo " +
                        "left join District as d on LI.ADistrict=d.DCode " +
                        "left join Taluk as t on LI.ADistrict=t.DCode and LI.ATaluk=t.TCode " +
                        "where LI.RegNo='" + strid + "'";

        SqlDataAdapter ad = new SqlDataAdapter(query, con);
        DataTable dt = new DataTable();
        ad.Fill(dt);

        if (dt.Rows.Count > 0)
        {
            Reg_no.Text = dt.Rows[0]["RegNo"].ToString().Trim();
            lbllice_no.Text = dt.Rows[0]["License_No"].ToString().Trim();
            isueDate.Text = dt.Rows[0]["Issue_Date"].ToString().Trim();
            validDate.Text = dt.Rows[0]["Valid_Date"].ToString().Trim();
            License_type.Text = dt.Rows[0]["Dealer_Region"].ToString().Trim();

            lblfee.Text = dt.Rows[0]["AmountPaid"].ToString().Trim();
            lblbranch.Text = dt.Rows[0]["BranchName"].ToString().Trim();
            lblpaiddate.Text = dt.Rows[0]["PaidDate"].ToString().Trim();
            Session["approved_by"] = dt.Rows[0]["Approved_by"].ToString().Trim();

            if (dt.Rows[0]["Photo"].ToString().Trim() != null || dt.Rows[0]["Photo"].ToString().Trim() != "")
            {
                Session["Photo"] = (byte[])dt.Rows[0]["Photo"];
                string encrypt_id = Utilities.encrypt(Utilities.convt("3"), ConfigurationManager.AppSettings["AadharEncKey"]);
                // img_dealer.ImageUrl = "Image.aspx?id=" + encrypt_id + "";
                Session["ImageUrl"] = "Image.aspx?id=" + encrypt_id + "";
            }
            else
            {
                // img_dealer.ImageUrl = null;
            }


            if (dt.Rows[0]["Approved_by"].ToString().Trim() == "8")
            {
                lbl_seal.Text = "Assistant Director of Agriculture";
                lbltplace.Text = dt.Rows[0]["TName"].ToString().Trim();
                lbldplace.Text = dt.Rows[0]["DName"].ToString().Trim();
            }
            else
            {
                lbl_seal.Text = "Joint Director of Agriculture";
                //lbldplace.Text = dt.Rows[0]["DName"].ToString().Trim();
            }

            DateTime today = DateTime.Today;
            lblname.Text = dt.Rows[0]["App_Name"].ToString().Trim();
            lblpname.Text = dt.Rows[0]["Sales_Adress"].ToString().Trim();
            lblrespon.Text = dt.Rows[0]["Responsible_person"].ToString().Trim();
            lblradres.Text = dt.Rows[0]["Respo_Adres"].ToString().Trim();
            ////lblrespoaadar.Text = dt.Rows[0]["Respo_adhar"].ToString().Trim();
            lblemail.Text = dt.Rows[0]["Respo_email"].ToString().Trim();
            lblmob.Text = dt.Rows[0]["Respo_Mob"].ToString().Trim();
            lblgeneDate.Text = dt.Rows[0]["Generated_Date"].ToString().Trim();


        }

    }

【问题讨论】:

  • 这能回答你的问题吗? a page can have only one server-side form tag
  • @SelimYıldız 正如我所说我没有此页面的任何母版页
  • 我们在这里遗漏了一些东西。在“查看源代码”中搜索“表单”,看看是否可以找到第二个?
  • @IrishChieftain 即使在“查看源代码”页面中也只显示一个表单标签
  • 你能展示 Uploading() 方法的代码吗?

标签: html asp.net xmlworker xmlworkerhelper


【解决方案1】:

当页面嵌入到母版页中并且该页面也有表单标记时,通常会发生这种情况。这很难说,因为我对项目结构一无所知。但这里有一些提示。由于您说您没有附加任何母版页,请检查该页面是否设置为附加到任何 _Layout.aspx 或任何其他布局页面。在 MVC 中,当您创建页面时,可以选择在布局页面中广告您的页面。

作为一种解决方法,我建议您从页面中删除现有的表单标签,然后查看页面的呈现方式。

【讨论】:

  • 如果我删除表单标签,它显示页面必须在服务器上包含一个表单标签
  • @chethu 你能把完整的代码贴在页面后面吗?至少页面加载方法?
  • @chethu 希望您的方法 export_click in 在页面背后的代码中,而不是在 aspx 中。还是这样?
猜你喜欢
  • 2011-08-16
  • 1970-01-01
  • 2015-10-15
  • 2014-12-07
  • 1970-01-01
  • 2014-06-26
  • 2012-08-29
  • 2011-02-24
相关资源
最近更新 更多