1
votes

Impossible d'évaluer l'expression car le code est optimisé lors de l'impression d'une page dans ASP.NET

Je reçois une exception "Impossible d'évaluer l'expression car le code est optimisé" lors de l'impression de la page.

Pour l'impression, j'utilise le générateur de chaînes pour ajouter le composant HTML, puis le placer dans Literal, puis attribuer littéralement à Session ["ctrl"]. J'utilise un nom de page Print.aspx et une fonction d'assistance PrintHelper.

protected void Page_Load(object sender, EventArgs e)
{
        try
        {
            Control ctrl = (Control)Session["ctrl"];
            PrintHelper.PrintWebControlStudentApp(ctrl);
        }
        catch(Exception ex)
        {
        }
 }

Print.aspx

private void PrintApplication(StudentDetails StudentData )
{
        List<StudentAttDetails> itemAtt = new List<StudentAttDetails>();
        List<StudentAcadDetails> itemAcad = new List<StudentAcadDetails>();
        itemAtt = StudentData.AttDetails;
        itemAcad = StudentData.AccDetails;

        try
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("<div class=' peopledetails-piims'>");
            sb.Append("<table class='blueTable'>");
            sb.Append("<tr>");
            sb.Append("<td colspan='2' style='font-size:1em;font-weight:bold;text-align-left;'>स्कूल की जानकारी, स्थिति व जगह</td><td colspan='2' style='font-size:1.2em;font-weight:bold;text-align-right;'>आवेदन क्रमांक:" + "</td>");
            sb.Append("</tr>");
            sb.Append("<tr>");
            sb.Append("<td>यूडाइस कोड:</td><td>" + StudentData.UdiseCode + "</td><td>सत्र:</td><td>" + StudentData.Session + "</td>");
            sb.Append("</tr>");
            sb.Append("<tr>");
            sb.Append("<td>कक्षा: </td><td>" + StudentData.Class + "</td><td>मधायम:</td><td>" + StudentData.Medium + "</td>");
            sb.Append("</tr>");
            sb.Append("<tr>");
            sb.Append("<td>आवेदन क्रमांक:  </td><td>" + StudentData.ApplicationId + "</td><td>विध्यार्थी का नाम:</td><td>" + StudentData.StudentName + "</td>");
            sb.Append("</tr>");
            sb.Append("<tr>");
            sb.Append("<td>जाति </td><td>:</td><td>" + StudentData.Caste + "</td><td>जन्मतिथि </td><td>:</td><td>" + StudentData.DOB + "</td>");
            sb.Append("</tr>");
            sb.Append("<tr>");
            sb.Append("<td>अभिभावक का नाम </td><td>:</td><td>" + StudentData.ParentsName + "</td><td>घर का पता </td><td>:</td><td>" + StudentData.Address + "</td>");
            sb.Append("</tr>");
            sb.Append("<tr>");
            sb.Append("<td>दाखिले का वर्ष </td><td>:</td><td>" + StudentData.YearOfJoin + "</td>");
            sb.Append("</tr>");
            sb.Append("</table>");

            //sb.Append("</br>");
            //sb.Append("</br>");

            sb.Append("<table class='blueTable'>");
            sb.Append("<thead>");
            sb.Append("<tr>");
            sb.Append("<td colspan='3' style='font-size:1em;font-weight:bold;text-align: center;'>उपस्थिति की जानकारी</td>");
            sb.Append("</tr>");
            sb.Append("</thead>");
            sb.Append("<thead>");
            sb.Append("<tr>");
            sb.Append("<th>SNo</th><th>वर्ष</th><th>बच्चे की उपस्थिति</th>");
            sb.Append("</tr>");
            sb.Append("</thead>");
            sb.Append("<tbody>");
            int snPreferences = 1;
            foreach (StudentAttDetails sad in itemAtt)
            {
                sb.Append("<tr>");
                sb.Append("<td>" + snPreferences.ToString() + "</td><td>" + (sad.Year).ToString() + "</td><td>" + sad.Attendance + "</td>");
                sb.Append("</tr>");
                snPreferences += 1;
            }
            sb.Append("</tbody>");
            sb.Append("</table>");

            //sb.Append("</br>");
            //sb.Append("</br>");


            sb.Append("<table class='blueTable'>");
            sb.Append("<thead>");
            sb.Append("<tr>");
            sb.Append("<td colspan='3' style='font-size:1em;font-weight:bold;text-align: center;'>विवरण की जानकारी</td>");
            sb.Append("</tr>");
            sb.Append("</thead>");
            sb.Append("<thead>");
            sb.Append("<tr>");
            sb.Append("<th>SNo</th><th>वर्ष</th><th>ग्रेड</th><th>कुल बच्चो की संख्या</th><th>कक्षा मे प्राप्त श्रेणी</th>");
            sb.Append("</tr>");
            sb.Append("</thead>");
            sb.Append("<tbody>");
            int sno = 1;
            foreach (StudentAcadDetails sacd in itemAcad)
            {
                sb.Append("<tr>");
                sb.Append("<td>" + sno.ToString() + "</td><td>" + (sacd.Year).ToString() + "</td><td>" + sacd.Grade.ToString() + "</td><td>" + (sacd.TotalStudent).ToString() + "</td><td>" + (sacd.Rank).ToString() + "</td><td>");
                sb.Append("</tr>");
                sno += 1;
            }
            sb.Append("</tbody>");
            sb.Append("</table>");
            sb.Append("</div>");

            ltlPrint.Text = "";
            ltlPrint.Text = sb.ToString();

            Session["ctrl"] = null;
            #region Print Application
            Session["ctrl"] = ltlPrint;
            ClientScript.RegisterStartupScript(typeof(Page), "onclick", "<script language=javascript>window.open('../Print.aspx','PrintMe','height=700px,width=700px,scrollbars=1');</script>");
            #endregion
        }
        catch (Exception ex)
        {
        }
}

J'obtiens une erreur sur la page Print.aspx où catch () lève une exception:

Impossible d'évaluer l'expression car le code est optimisé


0 commentaires

3 Réponses :


0
votes

Utilisez-vous une version de débogage? Ou une version de version, que pour Sure, le code est optimisé.


1 commentaires

Je ne comprends pas. Voulez-vous dire Reconstruire / Construire la solution et que faire le débogage?



0
votes
string url="";// In this Line you have to add url in proper way ...so you can easliy redirect 

string dim = "toolbar=0,fullscreen=1,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,maximize=0,height=1000px";

ScriptManager.RegisterStartupScript(this.Page, this.GetType(), Guid.NewGuid().ToString().Trim(), "window.open('" + url + "', 'Popup', '" + dim + "');", true);

1 commentaires

J'ai essayé la façon dont vous mentionnez ci-dessus, mais j'ai obtenu la même erreur.



1
votes

Vérifiez la page Page.aspx, le thread est abandonné en raison d'une certaine dépendance de votre système à la page maître. Merci


0 commentaires