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é
3 Réponses :
Utilisez-vous une version de débogage? Ou une version de version, que pour Sure, le code est optimisé.
Je ne comprends pas. Voulez-vous dire Reconstruire / Construire la solution et que faire le débogage?
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);
J'ai essayé la façon dont vous mentionnez ci-dessus, mais j'ai obtenu la même erreur.
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