Thursday, 24 September 2015

Write the Exception in Page view-source under body tag with HTML generic Controls

In some requirement the exception needs to be displayed in page view-source, so the below code will explain how to make it easily,

Code Sample:

                     try
            {
                //Error Occured
                SPSite _Site = new SPSite("Site URL");
               
            }
            catch (Exception ex)
            {
                //Catching the Exception
                System.Web.UI.HtmlControls.HtmlGenericControl dynDiv = new System.Web.UI.HtmlControls.HtmlGenericControl("DIV");
                dynDiv.ID = "dynDivCode";
                dynDiv.InnerHtml = "\n<!--EVL Exception BeginTag-->\n<!--"+ex.Message+"-->\n<!--EVL Exception EndTag-->\n";
                this.Controls.Add(dynDiv);
              
            }

No comments:

Post a comment