Tuesday, August 2, 2011

Asp.Net Interview Questions

    For Freshers or Experienced, check these interview questions. Seasoned - 2011 ( Experience Level: 0 to 3+ ).
  • Questions mainly related to OOPS, DotNet, ASp.Net, SQL-Server, javascript (and bits of CSS, WCF).
  • also covered slip-test, system tests, some frequently asked basic questions.
  • Note: only important questions are covered and not all the basic questions included (assuming you already aware of basics).
  • No detailed description is provided as answers to questions, you need to refer other sources (books,internet) for complete details.
  • These are the questions which i have experienced and encountered.

Download or View the document from: doc.google.

Asp.Net: Passing Gridview control from one page to another page

Hi,
    In this post, i will explain how to get gridview control defined in one page into another page. This is accomplished with "Page.PreviousPage" property.
    Let Page1.aspx contains a gridview control and we want this gridview (or any object) be passed to another page called page2.aspx.
We try this goal in two alternatives ways:

  • Button with PostBackUrl="Page2.aspx" attribute.

  • Server.Transfer("Page2.aspx", true); by coding.


In page1.aspx define:

  • Gridview control named - grid

  • Button with postbackUrl="page2.aspx" - btn1

  • and another Button with click-event - btn2


Markup:

<asp:GridView ID="grid" runat="server" AutoGenerateColumns="false" />
<hr/>
<asp:Label runat="server" Text="Testing Gridview access to next-Page, try below buttons"></asp:Label>
<br />
<asp:Button ID="btn1" runat="server" PostBackUrl="Page2.aspx" Text="NextPageDirect" />
(or) serverTransfer:
<asp:Button ID="btn2" runat="server" Text="NextPageAtServer" OnClick="btn2_Click" />

Code:

//Testing Gridview data access from one page to next page.
public partial class Page1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
FillGrid(); //Your logic to fill gridview
}
}

public GridView Getgrid
{
get { return this.grid; } //ViewState should be enabled for gridview.
}

protected void btn2_Click(object sender, EventArgs e)
{
Server.Transfer("Page2.aspx", true);
}
}



In Page2.aspx define:
Form control (default markup added by VS)
Code:

public partial class Page2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Page1 pg = Page.PreviousPage as Page1;
if (pg != null)
{
GridView grid = pg.Getgrid;
form1.Controls.Add(grid);
}
}
}

Now Open the Page1.aspx from browser (or, run from VisualStudio).



Above is the screenshot of Page1.aspx




Page2 screenshot after button click in Page1



Using the above technique and custom public properties, we can access any object from page1 to page2.

Asp.Net: Page with 2 Form controls

Hi,

    As we know, Asp.Net not allows more than one <form runat="server"> tag in webForm (page). What if we need 2 <form> tags on the same page?
In this post, i will explain how to maintain 2 <form> tags in a single webForm.

Let Default.aspx is the main page, write the usual Asp.Net form tag:
<form id="form1" runat="server">
and then write another HTML form tag (without runat="server" attribute):
<form id="form2" action="UILessPage.aspx" method="post">
in the same page.
    The trick is form2 posts its data to "UILessPage.aspx" instead of "Default.aspx", because, we want data from form2 be handled separately instead of mingling with Default.aspx code.
This makes easy to understand and maintain the Form data. The UILessPage.aspx page contains no UI (markup) for itself, its job is only handling the form2 data, we can even make this page not accessible if accessed directly from browser.



Above is the screenshot of Default.aspx with 2 forms

Note:
  • The Form2 should contain only HTML controls .
  • Form1 can contain WebServer controls.


Please download and check the code to understand how to retrieve the submitted data from form2. I used the "Request.Form[CtrlName]" to get the HTML control values from form2.

Download:
download the code files as zip from here.

Asp.Net: Ajax accesses compressed DataURI Image

Hi,

    Here i will explain, how to get image data using Ajax technique. This sample post shows an example of what can be possible with
DataURI, base64 compression and Ajax.

Covering the topics:
  • how to convert image to base64,
  • compress this data and access it via ajax from browser and
  • assign it to <img> tag as DataURI.

    By placing the images in a file called Resource.resx, we can easily generate base64 encoding. For further information on Resource file, check my previous post and check this tip on my other blog for full details: Image to base64 conversion.

Compression support depends on the browser. If it supports, we can use either GZip or Deflate to compress the data. Using AJAX, request this base64 data and assign it to <img> tag as source, with appropriate headings added (datauri, imagetype etc).

These are the files which I have used for this sample:
  • webForm (aspx) which contains Ajax code and <img> tags.
  • Handler file (ashx) which handles the ajax requests, compresses the base64 data from Resource.resx file.
  • Resource.resx file is a xml file, contains the embedded images in base64 format.
Note:

  • If the image size is small, around <5kb, don't use the compression, as it takes extra space instead of lowering.
  • IE8 accepts data URIs with a maximum length of 32 KB.
  • After the image is compressed, we gain around 2KB of space.

Reference:
http://en.wikipedia.org/wiki/Data_URI_scheme
Download:
download the code files as zip from here.