- This example needs jquery library,which is already included in Visual Studio 2010
- Paste the following code inside the <head> tag
- <script type="text/javascript" src="Scripts/jquery-1.4.1.js"></script>
- <style type="text/css">
- .active
- {
- background-color:Red;
- color:White;
- border:1px solid gray;
- }
- .accordion h3
- {
- border:1px solid red;
- padding:0px;
- margin:0px;
- }
- .accordion p
- {
- background-color:Aqua;
- color:Black;
- border:1px solid black;
- padding:0px;
- margin:0px;
- height:100px;
- }
- </style>
- <script type="text/javascript">
- $(document).ready(function () {
- $('.accordion h3:first').addClass("active"); $('.accordion p:not(:first)').hide();
- $('.accordion h3').click(function () {
- $(this).addClass("active").siblings("h3").removeClass(); $(this).next("p").slideDown("slow");
- $(this).next("p").siblings("p:visible").slideUp("slow");
- });
- });
- </script>
- Paste the following code inside the <body>tag
- <div class="accordion" style="border:1px solid red; width:200px">
- <h3>
- Salim
- </h3>
- <p>
- Father</p>
- <h3>
- Shanti
- </h3>
- <p>
- Mother</p>
- <h3>
- Shahnaz
- </h3>
- <p>
- Sister</p>
- <h3>
- Sajid
- </h3>
- <p>
- Me</p>
- <h3>
- Abid
- </h3>
- <p>
- Brother</p>
- </div>
DOT NET
Monday 14 May 2012
Jquery Accordion
Thursday 19 April 2012
C# Interview Questions Answers
What’s the advantage of using System.Text.StringBuilder over System.String?
StringBuilder is more efficient in the cases, where a lot of manipulation is done to the text. Strings are immutable, so each time it’s being operated on, a new instance is created.
Can you store multiple data types in System.Array?
No.
What’s the difference between the System.Array.CopyTo() and System.Array.Clone()?
The first one performs a deep copy of the array, the second one is shallow.
How can you sort the elements of the array in descending order?
By calling Sort() and then Reverse() methods.
What’s the .NET datatype that allows the retrieval of data by a unique key?
HashTable.
What’s class SortedList underneath?
A sorted HashTable.
Will finally block get executed if the exception had not occurred?
Yes.
What’s the C# equivalent of C++ catch (…), which was a catch-all statement for any possible exception?
A catch block that catches the exception of type System.Exception. You can also omit the parameter data type in this case and just write catch {}.
Can multiple catch blocks be executed?
No, once the proper catch code fires off, the control is transferred to the finally block (if there are any), and then whatever follows the finally block.
What’s a delegate?
A delegate object encapsulates a reference to a method. In C++ they were referred to as function pointers.
What’s a multicast delegate?
It’s a delegate that points to and eventually fires off several methods.
How’s the DLL Hell problem solved in .NET?
Assembly versioning allows the application to specify not only the library it needs to run (which was available under Win32), but also the version of the assembly.
What are the ways to deploy an assembly?
An MSI installer, a CAB archive, and XCOPY command.
What’s a satellite assembly?
When you write a multilingual or multi-cultural application in .NET, and want to distribute the core application separately from the localized modules, the localized assemblies that modify the core application are called satellite assemblies.
What namespaces are necessary to create a localized application?
System.Globalization, System.Resources.
What’s the difference between // comments, /* */ comments and /// comments?
Single-line, multi-line and XML documentation comments.
How do you generate documentation from the C# file commented properly with a command-line compiler? Compile it with a /doc switch.
What’s the difference between <c> and <code> XML documentation tag?
Single line code example and multiple-line code example.
Is XML case-sensitive?
Yes, so <Student> and <student> are different elements.
What debugging tools come with the .NET SDK?
CorDBG – command-line debugger, and DbgCLR – graphic debugger. Visual Studio .NET uses the DbgCLR. To use CorDbg, you must compile the original C# file using the /debug switch.
What does the This window show in the debugger?
It points to the object that’s pointed to by this reference. Object’s instance data is shown.
What does assert() do?
In debug compilation, assert takes in a Boolean condition as a parameter, and shows the error dialog if the condition is false. The program proceeds without any interruption if the condition is true.
What’s the difference between the Debug class and Trace class?
Documentation looks the same. Use Debug class for debug builds, use Trace class for both debug and release builds.
Why are there five tracing levels in System.Diagnostics.TraceSwitcher?
The tracing dumps can be quite verbose and for some applications that are constantly running you run the risk of overloading the machine and the hard drive there. Five levels range from None to Verbose, allowing to fine-tune the tracing activities.
Where is the output of TextWriterTraceListener redirected?
To the Console or a text file depending on the parameter passed to the constructor.
How do you debug an ASP.NET Web application? Attach the aspnet_wp.exe process to the DbgClr debugger.
What are three test cases you should go through in unit testing?
Positive test cases (correct data, correct output), negative test cases (broken or missing data, proper handling), exception test cases (exceptions are thrown and caught properly).
Can you change the value of a variable while debugging a C# application?
Yes, if you are debugging via Visual Studio.NET, just go to Immediate window.
Explain the three services model (three-tier application).
Presentation (UI), business (logic and underlying code) and data (from storage or other sources).
What are advantages and disadvantages of Microsoft-provided data provider classes in ADO.NET? SQLServer.NET data provider is high-speed and robust, but requires SQL Server license purchased from Microsoft. OLE-DB.NET is universal for accessing other sources, like Oracle, DB2, Microsoft Access and Informix, but it’s a .NET layer on top of OLE layer, so not the fastest thing in the world. ODBC.NET is a deprecated layer provided for backward compatibility to ODBC engines.
What’s the role of the DataReader class in ADO.NET connections?
It returns a read-only dataset from the data source when the command is executed.
What is the wildcard character in SQL?
Let’s say you want to query database with LIKE for all employees whose name starts with La. The wildcard character is %, the proper query with LIKE would involve ‘La%’.
Explain ACID rule of thumb for transactions.
Transaction must be Atomic (it is one unit of work and does not dependent on previous and following transactions), Consistent (data is either committed or roll back, no “in-between” case where something has been updated and something hasn’t), Isolated (no transaction sees the intermediate results of the current transaction), Durable (the values persist if the data had been committed even if the system crashes right after).
What connections does Microsoft SQL Server support?
Windows Authentication (via Active Directory) and SQL Server authentication (via Microsoft SQL Server username and passwords).
Which one is trusted and which one is untrusted?
Windows Authentication is trusted because the username and password are checked with the Active Directory, the SQL Server authentication is untrusted, since SQL Server is the only verifier participating in the transaction.
Why would you use untrusted verificaion?
Web Services might use it, as well as non-Windows applications.
What does the parameter Initial Catalog define inside Connection String?
The database name to connect to.
What’s the data provider name to connect to Access database?
Microsoft.Access.
What does Dispose method do with the connection object?
Deletes it from the memory.
What is a pre-requisite for connection pooling?
Multiple processes must agree that they will share the same connection, where every parameter is the same, including the security settings.
Wednesday 18 April 2012
Search Engine Friendly (SEO) Tips for ASP.Net Sites
1. Add descriptive and unique Page Title for every page
Every page in your website should have a unique and descriptive page title that can describe what the page offers. You can set the Page Title either declaratively or in the code behind file. Refer below,
In ASPX,
<%@ Page Language="C#" AutoEventWireup="true" Title="My Home Page" CodeFile="Default.aspx.cs" Inherits="_Default" %>
In code behind,
Page.Title = "My Home Page";
2. Links should be hyperlinks, no linkbutton or javascript navigation for crawlable links
Make sure all your links in your page are hyperlinks. Search engines can crawl a page only if it is linked through a hyper link(anchor tag). Javascript navigations are not search engine friendly since search engines will not understand it.
3. Use javascript navigation for site related pages that have no search values
Page rank is distributed across the links on your page. Some of the internal website pages like About us, disclaimer, Registration, login, contact us, user profile pages can be navigated through javascript so that the page rank are not distributed to them. Doing like this will make rest of the crawlable content links benefited.
4. Add Meta Keyword and Description tag for every page
Add Meta keyword and Meta description tag with relevant contents. Search engines will use these tags to understand what the page offers. You can dynamically set the meta tags from codebehind file using the below code,
HtmlHead head = (HtmlHead)Page.Header;
HtmlMeta metasearch1 = new HtmlMeta();
HtmlMeta metasearch2 = new HtmlMeta();
metasearch1.Name = "descriptions";
metasearch1.Content = "my personal site";
head.Controls.Add(metasearch1);
metasearch2.Name = "keywords";
metasearch2.Content = "ASP.Net,C#,SQL";
head.Controls.Add(metasearch2);
The above code will add the below Meta tags to output html.
<meta name="descriptions" content="my personal site" />
<meta name="keywords" content="ASP.Net,C#,SQL" />
In ASP.Net 4.0, Microsoft added 2 new properties on the Page directive (Page object) that lets you to define the Meta keywords and Description declaratively and dynamically from codebehind.
In ASPX,
<%@ Page Language="C#" AutoEventWireup="true" MetaKeywords="asp.net,C#" MetaDescription="This is an asp.net site that hosts asp.net tutorials" CodeFile="Default.aspx.cs" Inherits="_Default" %>
In codebehind,
protected void Page_Load(object sender, EventArgs e)
{
Page.MetaKeywords = "asp.net,C#";
Page.MetaDescription = "This is an asp.net site that hosts asp.net tutorials.";
}
The similar can thing can be achieved in previous versions of .NetFramework by using a custom BasePage class. Read the below article to know more.
Adding Custom Property to Page Directive in ASP.Net 2.0
5. Make descriptive urls
Make your website URL descriptive. URL’s that has lots of query string values, numeric ids are not descriptive. It will provide enough information what the page offers. For example, http://www.example.com/products.aspx?catid=C91E9918-BEC3-4DAA-A54B-0EC7E874245E is not descriptive as http://www.example.com/Electronics
Apart from other parameters, search engines will also consider the website url to match your page for a searched keywords.
Read the below article in codedigest.com to make search engine friendly url’s in asp.net.
Search Engine Friendly URL’s Using Routing in ASP.Net 3.5
You can also use URL rewriting modules for this.
6. Add Alt for images, Title for Anchor
Add ALT text for images and Title for hyperlinks. The ALT text will be displayed when the browser cannot display the image for some reasons. Search engines will not be able to read the image and ALT text will give some hint about the image which the search engine can use.
<asp:Image ID="imLogo" runat="server" AlternateText="My company Logo" ImageUrl="logo.gif" />
<asp:HyperLink ID="hpHome" runat="server" ToolTip="My Website Home" Text="Home" NavigateUrl="Home.aspx"></asp:HyperLink>
The above ASP.Net markup will produce the below output,
<img id="imLogo" src="logo.gif" alt="My company Logo" style="border-width:0px;" />
<a id="hpHome" title="My Website Home" href="Home.aspx">Home</a>
7. Handle ViewState properly, don’t overload the ViewState
ViewState is an encoded string that is populated by ASP.Net to maintain the state of the controls on postback. This string is saved to a hidden field at the top of every page and gets transported with the HTML output. Most of the times, the ViewState string will be long and heavier. Since ViewState has no search value, it will be a real hindrance for search engines when trying to find the real content in your page. Some search engine may have some restriction on the page size.
Hence, try to handle the ViewState in your page efficiently. Turn off ViewState for the control that doesn’t require it.
You can set EnableViewState="false" to turn off viewstate at control level, page level(@Page directive) and config level(<pages> section).
8. Design your page lighter with less images, less flash and less Silverlight content
Try to design your page with very less media contents like images, flash objects, Silverlight objects, ActiveX objects, etc. Search engines can only read HTML contents. A page that is entirely build on flash or Silverlight are not search engine friendly since the search engine robots cannot find any textual contents in those pages.
9. Do Permanent Redirect with proper return codes to retain the Page Rank
If you have moved a page to a different URL or changed your domain to new domain then you should do a redirect to the new location by returning an http status code of 301- Permanent Redirect. This is called permanent redirection. This will make sure the existing page rank is copied to the new page.
Read the below codedigest article that discusses some of the scenario where we can use permanent redirect for search engine optimization.
How to Redirect URLs/domain Without www to With www and vice versa - Permanent Redirection in ASP.Net?
SEO improvements in ASP.Net 4.0
10. Add rel=”nofollow” to external links
Add rel=”nofollow” to the user contributed links that are external to the site. Sometimes, the external links posted by a user may have security threats (it may download a malware which will infect the users) or possibly a spam generating site. Doing like this will secure your site from getting penalized from search engines.
Sometime back when you add rel=”nofollow” to an anchor tag, search engines will not share the page rank with that link. This makes the remaining links on the page to take more share of the page rank. Currently, the implementation is changed where the page rank is shared but it no longer allows other links on the page to take more of the share. Read here to know more about how nofollow affect the page rank previously and now.
11. Use Header tags
Use Header tags (H1,H2, H3, H4, H5 and H6) wherever appropriate instead of styling the text in SPAN tags. These Header tags are search engine friendly. You can use this tag efficiently to organize your page headings and sub headings.
For example, you can put your page top most heading in H1, sub heading in H2, sub-sub heading in H3, etc that represents a proper hierarchy of your page contents.
12. No inline CSS styles and Javascript codes
Always keep your CSS styles and javascript defined in a separate file. This makes your page clean, simple and light-weight. The search engines can find the page content easily and can efficiently index it.
13. Unique URL for a Page
Search engines like Google will treat a page with url http://www.example.com/Default.aspx as different from http://example.com/Default.aspx even though they are serving the same page on a website. This may lead to penalize your website for duplicate content issue by the search engine. Hence, always allow single unique URL to identify a page. You can handle this scenario by doing a permanent redirect to one url. Read the below article to handle these scenario in ASP.Net.
How to Redirect URLs/domain Without www to With www and vice versa - Permanent Redirection in ASP.Net?
You can also Google Webmaster Tools for doing this restriction.
14. Make SEO friendly pagers
Always construct search engine friendly pager links when displaying list of items in a summary page. For example, product list, article list page, etc. A link is called search engine friendly if it is anchor tag (<A>) that has a reachable url in its href property through GET request.
Read the below article to build search engine friendly pager for GridView control in Asp.Net.
Search Engine Friendly Pager for ASP.Net GridView control
15. Limit the number of links per page
Previously there was a limit in number of links (100 links per page) the Google search engine will index on a page. This restriction is now no more. But it is still advisable to have limited number of links in your pages to avoid any adverse effect on your site rank. This is to prevent link spamming and to preserve the page rank.
16. Build SiteMap
Always have a sitemap file that can guide users and search engines to navigate your site pages easily. It is really necessary to have 2 site maps for a site, an xml sitemap file used by the search engines and an html sitemap file for the website users. Refer here to know more creating xml sitemap for search engines. You can submit your xml sitemap or RSS feed to Google Webmaster tools.
Friday 13 April 2012
Loading Master Page Dynamically
Add a master page in your solution explorer and named it as "MasterPage.master"
Paste the following code in between div tag
<table width="100%">
<tr>
<td style="background-color: Red; color: White; height: 70px; width: 700px; font-size: x-large"
align="center">
Master Page1
</td>
<td style="background-color: Aqua; color: Black; height: 70px" align="center">
<asp:LinkButton ID="LinkButton1" ForeColor="Black" runat="server" OnClick="LinkButton1_Click">Master Page 1</asp:LinkButton>
<asp:LinkButton ID="LinkButton2" ForeColor="Black" runat="server" OnClick="LinkButton2_Click">Master Page 2</asp:LinkButton>
</td>
</tr>
<tr>
<td colspan="2" style="background-color: ButtonFace; height: 300px">
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</td>
</tr>
</table>
Add one more master page in your solution explorer and named it as "MasterPage2.master"
Paste the following code in between div tag
<table width="100%">
<tr>
<td style="background-color: Lime; color: Black; height: 70px; width: 700px; font-size: x-large"
align="center">
Master Page2
</td>
<td style="background-color: Red; color: White; height: 70px" align="center">
<asp:LinkButton ForeColor="White" ID="LinkButton1" runat="server" OnClick="LinkButton1_Click">Master Page 1</asp:LinkButton>
<asp:LinkButton ForeColor="White" ID="LinkButton2" runat="server" OnClick="LinkButton2_Click">Master Page 2</asp:LinkButton>
</td>
</tr>
<tr>
<td colspan="2" style="background-color: ButtonFace; height: 300px">
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</td>
</tr>
</table>
</div>
Paste the following code in MasterPage.master.cs and MasterPage2.master.cs files
protected void LinkButton1_Click(object sender, EventArgs e)
{
Response.Redirect("Default.aspx?master=First");
}
protected void LinkButton2_Click(object sender, EventArgs e)
{
Response.Redirect("Default.aspx?master=Second");
}
Add a new Web Form and named it as "Default.aspx" and set its default master page,that is "MasterPage.master"
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
Paste the following code in _Default class in Default.aspx.cs file
protected void Page_PreInit(object sender, EventArgs e)
{
if (Request["master"] != null)
{
switch (Request["master"].ToString())
{
case "First":
Page.MasterPageFile = "MasterPage.master";
break;
case "Second":
Page.MasterPageFile = "MasterPage2.master";
break;
}
}
}
Paste the following code in between div tag
<table width="100%">
<tr>
<td style="background-color: Red; color: White; height: 70px; width: 700px; font-size: x-large"
align="center">
Master Page1
</td>
<td style="background-color: Aqua; color: Black; height: 70px" align="center">
<asp:LinkButton ID="LinkButton1" ForeColor="Black" runat="server" OnClick="LinkButton1_Click">Master Page 1</asp:LinkButton>
<asp:LinkButton ID="LinkButton2" ForeColor="Black" runat="server" OnClick="LinkButton2_Click">Master Page 2</asp:LinkButton>
</td>
</tr>
<tr>
<td colspan="2" style="background-color: ButtonFace; height: 300px">
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</td>
</tr>
</table>
Add one more master page in your solution explorer and named it as "MasterPage2.master"
Paste the following code in between div tag
<div><table width="100%">
<tr>
<td style="background-color: Lime; color: Black; height: 70px; width: 700px; font-size: x-large"
align="center">
Master Page2
</td>
<td style="background-color: Red; color: White; height: 70px" align="center">
<asp:LinkButton ForeColor="White" ID="LinkButton1" runat="server" OnClick="LinkButton1_Click">Master Page 1</asp:LinkButton>
<asp:LinkButton ForeColor="White" ID="LinkButton2" runat="server" OnClick="LinkButton2_Click">Master Page 2</asp:LinkButton>
</td>
</tr>
<tr>
<td colspan="2" style="background-color: ButtonFace; height: 300px">
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</td>
</tr>
</table>
</div>
Paste the following code in MasterPage.master.cs and MasterPage2.master.cs files
protected void LinkButton1_Click(object sender, EventArgs e)
{
Response.Redirect("Default.aspx?master=First");
}
protected void LinkButton2_Click(object sender, EventArgs e)
{
Response.Redirect("Default.aspx?master=Second");
}
Add a new Web Form and named it as "Default.aspx" and set its default master page,that is "MasterPage.master"
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
Paste the following code in _Default class in Default.aspx.cs file
protected void Page_PreInit(object sender, EventArgs e)
{
if (Request["master"] != null)
{
switch (Request["master"].ToString())
{
case "First":
Page.MasterPageFile = "MasterPage.master";
break;
case "Second":
Page.MasterPageFile = "MasterPage2.master";
break;
}
}
}
Thursday 12 April 2012
ASP.NET version 4 introduces new features
- Core services, including a new API that lets you extend caching, support for compression for session-state data, and a new application preload manager (autostart feature).
- Web Forms, including more integrated support for ASP.NET routing, enhanced support for Web standards, updated browser support, new features for data controls, and new features for view state management.
- Web Forms controls, including a new Chart control.
- MVC, including new helper methods for views, support for partitioned MVC applications, and asynchronous controllers.
- Dynamic Data, including support for existing Web applications, support for many-to-many relationships and inheritance, new field templates and attributes, and enhanced data filtering.
- Microsoft Ajax, including additional support for client-based Ajax applications in the Microsoft Ajax Library.
- Visual Web Developer, including improved IntelliSense for JScript, new auto-complete snippets for HTML and ASP.NET markup, and enhanced CSS compatibility.
- Deployment, including new tools for automating typical deployment tasks.
- Multi-targeting, including better filtering for features that are not available in the target version of the .NET Framework.
Join Us:http://anybodycancode.com
Subscribe to:
Posts (Atom)