header1.html

Sunday 21 September 2014

'Thread was being aborted' –Exception for Response.Redirect() method inside try-catch block

If you are monitoring errors of your application you might have noticed that in your error log file lots of 'Thread was being aborted' exception logged.
This Exception occurs when you use Response.Redirect inside of a Try / Catch block. Your code will work and the browser will be redirected but that is reason of getting lots of alerts.
If you are passing QueryString then your application may not work properly because of this issue, so it is important to handle or avoid this kind of exceptions.
There are different ways to resolve this issue,

  • Simplest way to move the Response.Redirect outside the Try/Catch block. 
  • Catch Exception and do nothing, 
                 try 
                    { 
                        if (Condition) 
                          Response.Redirect("newpage.aspx”); 
                    } 
                catch (ThreadAbortException ex) 
                 { // do nothing } 
                 catch (Exception e) 
                  { //Write your Error log logic } 
  • Use overload of Redirect method like, Pass false as second parameter to this overload. Response.Redirect("newpage.aspx”,false); 
I prefer to use 3rd approach as it is easiest one to implement and it works fine in case if you are using QueryString in your application.

Hope this helps you someway. Thank you!!!

Sunday 20 July 2014

What is XSLT?How to Transform XML data using XSLT?

In this post we are going to discuss about-How we can display XML content?There are multiple ways to do to so,but XSLT is best suitable way.So,what is XSLT?

To know about XSLT: Extensible Stylesheet Language Transformation, we should have the basic idea of following,

What is a Markup Language?

A language specially designed for processing, defining and presenting text/data is called a Markup Language.

To know about XSLT, we should have the basic idea of following.

There are three languages in XSL family,

  1. XSL Transformations(XSLT): XML language for transforming XML Documents.
  2. XSl  Formatting Objects (XSL-FO):XML language for specifying the visual formatting of an XML document.
  3. XML Path Language (XPATH): a non XML language used by XSLT, and also available for use in non-XSLT contexts, for addressing the parts on an XML document.

  • XSLT helps to transform one XML document to another. Output of XSL transformation can be another XML, HTML or PDF. Data from one XML can be read and modified into another applying arithmetic, numeric, string operations based on the need.
  • XSLT was developed by W3C especially for XML. XSLT internally uses XPATH and XSL-FO for navigating, performing calculation and for formatting the data.
  • XSLT documents are well-formed XML documents that describe how another XML document should be transformed. For XSLT to work, it needs an XML document to transform and an engine to make the transformation take place. In addition, parameters can be passed in to XSLTs providing further instructions on how to do the transformation.
Why and where is it used?

In web application, web services sent the business data in form of XML within the Applications and across the applications. Since XML is accepted as the most common mode of storing and passing data, a language is needed to read the XML in different ways for different application.


A medium like XSLT is needed to parse the data from XML and give it to browsers to render the HTML code. XSLT works in between XML and Browser to transform the data.


Example:

Blog.xml

<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="BlogsStyle.xsl"?>
<Blogs>
       <name id="21">
                <bname>Career Web Helper</bname>
                <Topics>Online Quizzes,MCQs and Articles on Microsoft Technologies.</Topics>
       </name>
                   <place>Pune</place>
                   <language>English</language>
</Blogs>

BlogsStyle.xsl

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version='1.0'>
<xsl:output method="html" indent="yes" omit-xml-declaration="yes" encoding="utf-8"/>
<xsl:template match="Blogs">
<html>
<body>
   <h2>Blog Detail</h2>
   <table border="1">
     <tr>
       <td bgcolor="gray">Blog Id</td>
       <td><xsl:value-of select="name/@id"/></td>
     </tr>
     <tr>
       <td bgcolor="gray">Blog Name</td>
       <td><xsl:value-of select="name/bname"/></td>
     </tr>
      <tr>
       <td bgcolor="gray">Topics Covered</td>
       <td><xsl:value-of select="name/Topics"/></td>
     </tr>
     <tr>
       <td bgcolor="gray">Place</td>
       <td><xsl:value-of select="place"/></td>
     </tr>
     <tr>
       <td bgcolor="gray">Language</td>
       <td><xsl:value-of select="language"/></td>
     </tr>
   </table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

Output:

Sample Basic XSLT Example

This is only basic of XSLT,we will cover some advance topics in upcoming posts. Hope you like this post. 


Saturday 26 April 2014

JavaScript Quiz


JavaScript Quiz
1.Which of the following is not an event in JavaScript?
onunload
onremove
ondblclick
onchange


2.True or False-"All variables are of object type in JavaScript".
True
False


3.What will be o/p of "2"+2+1 JavaScript statement?
5
221
23
Error


4.What Built-in javascript function back() does?
Returns to previous function
Closes the specified window
Returns to the previous URL
No such function


5. A ________ box allows the user to enter input by providing a text box.
confirm
prompt
alert
drop


6.Which of the following looping structure is not available in JavaScript ?
for
while
do-while
foreach


7.The Undefined value Javascript means the variable used in code doesn't exist or is not assigned any value or the property doesn't exist.Ture or False?
Ture
False


8.How to disable an HTML object using JavaScript?
document.getElementById("myObject").visible = false;
document.getElementById("myObject").disabled = true;
document.getElementById("myObject").visibility = false;
document.getElementById("myObject").disable = true;


9.It is easy to manipulate cookies in JavaScript with the document.cookie property.True/False?
True
False



10.What will be o/p of 2+1+"3" JavaScript statement?
213
6
33
Error


Sunday 26 January 2014

Javascript MCQs(Multiple Choice Questions)


Hello All first I would like to Wish you all Happy New year 2014,so before going to new post here are some last years Successful popular posts,
1)CRUD operation using Entity Framework and LINQ
2)Basic Web Development MCQs
3)New Features of VS 2013 Developers Perspective
4)WCF Online Quiz or WCF MCQs
and many more are there so please visit them and do share,like & comment on it.
1.What will be result of following javascipt function
<script type="text/javascript">
var name = "CareerWebHelper";
function DisplayName () {
var name = "Sagar"; 
document.write(name); 
}
</script>
A.CareerWebHelper
B.Sagar
C.Error
D.None of above
Click for answer 

B.Sagar
2.What will be result of following javascipt function
<script type="text/javascript">
var name1 = "WCF MCQs";
function DisplayName () {
var name2 = " Online"; 
document.write(name1+name2); 
}
</script>
A.WCF MCQsOnline
B.WCF MCQs Online
C.Object required error
D.Javascript Error
Click for answer 

B.WCF MCQs Online
3.What will be result of following javascipt function?
<script type="text/javascript">
var name1 = "WCF quiz";

function DisplayName () {
 var name2 = "ASP.NET MCQs";
if(name1 != "") 
document.write(name1);
else
document.write(name2);
 
}
</script>
A.Javascript Error at else statement
B.ASP.NET MCQs
C.WCF quiz
D.Javascript Error in if condition
Click for answer 

C.WCF quiz
4.What will be result of following javascipt function?
<script type="text/javascript">
var name1 = "WCF quiz";

function DisplayName () {
 var name2 = "ASP.NET MCQs";
 (name1 != ""?document.write(name2):document.write(name1));
}
</script>
A.WCF quiz
B.ASP.NET MCQs
C.Javascript Error near conditional statement
D.Nothing will happen
Click for answer 

B.ASP.NET MCQs
5.What will be result of following javascipt function?
<script type="text/javascript">
var name1 = "";

function DisplayName () {
 var name2 = "ASP.NET MCQs";
 if(name1 = "")
document.write("name1 is null");
else
document.write(name2);
 
}
</script>
A.name1 is null
B.Error near name1 declaration
C.No result
D.ASP.NET MCQs
Click for answer 

D.ASP.NET MCQs
6.What will be result of following javascipt function?
<script type="text/javascript">
var name1 = "WPF Quiz";

function DisplayName () {
 var name2 = "ASP.NET MCQs";
 if(name1 = "WPF Quiz")
document.write("name1 is not null");
else
document.write(name2);
 
}
</script>
A.ASP.NET MCQs
B.Error near if statement
C.name1 is not null
D.None of above
Click for answer 

C.name1 is not null
7.What will be result of following javascipt function?
<script type="text/javascript">
var name1 = "WPF Quiz";

function DisplayName () {
 var name2 = "ASP.NET MCQs";
 (name1.replace('P','C')=="WCF Quiz"?document.write(name1):document.write(name2));
}
</script>
A.WPF Quiz
B.WCF Quiz
C.ASP.NET MCQs
Click for answer 

A.WPF Quiz
8.What will be result of following javascipt function?
<script type="text/javascript">
var name1 = "WPF Quiz";
function DisplayName () {
 var name2 = "ASP.NET MCQs";
 name1=name1.replace('P','C');
 document.write(name1);
}
</script>
A.WCF Quiz
B.WPF Quiz
C.ASP.NET MCQs
D.Error in statement near replace()
Click for answer 

A.WCF Quiz