Saturday, February 26, 2011

Dot net Interview:

1. Which Control has a faster performance?
     a) Data List
     b) Data Grid
     c) Repeater
  Ans: Repeater

2. Base class included in All the webform Pages.
  Ans: System.Web.UI.Page

3. Is String is Value Type OR Referance Type?
  Ans: Reference type.

4. What is Smart Navigation?
  Ans: Cursor position is maintained when the Page gets refreshed due to server side validation. This is called  smart navigation.

5. How ASP.net is different from ASP?
  Ans: In ASP.net scripting is seperated from the HTML code & is compiled as a DLL. This DLL can be executed   on the server.

6. Whst is the use of @page directive?
  Ans: @page directive is used to specify attributes that affects the page in the .aspx page.

7. What is deligates?
  Ans: A deligate is an object that holds the referance to a method.

8. How does asp.net works?
  Ans: When browser requests an asp.net page or file, IIS passes the request to the asp.net engine on the   server. Asp.net engine reads the file line by line, and executes the scripts in the file. Finally the asp.net file is   returned to the browser as a Plain HTML.

9. What is Stored Procedure in SQL?
  Ans: Stored Procdure is already written SQL statments, that is Stored in the database.

10. Explain Execute Scalar in SQL?
  Ans: Executes the query and returns only the first column of the first row in the result set. i.e. It retrives  single value.

11. what is the name space for Unit Testing?
  Ans: Microsoft.VisualStudio.Testtools.Unittesting;

12. Trace and Debug belongs to which namespaces?
  Ans: System.Diagnostics;

13. What are Assemblies?
  Ans: Assemblies are similar to dll files. Both has the reusable pieces of code in the form of classes/ functions. Dll needs to be registered but assemblies have its own metadata.

14. What is code-based security?
  Ans: Determining whether or not a piece of code is allowed to execute & what resources it can use during  execution.

15. Differance between Convert.Tostring() and .Tostring().
  Ans: Both are same, but .Tostring() cant handle null values and will thro null referance exception.
  Where as Convert.tostring() handles null values.

Sunday, February 6, 2011

Creating Simple Poll Vote system using text file in back end.

On Code bind :

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        int yes;
        int no;
        string filename = Server.MapPath("filesave.txt");
        StreamReader objreader = new StreamReader(filename);
        string line = objreader.ReadLine();
        string[] args= line.Split('|');
        yes = int.Parse(args[0].ToString());
        no = int.Parse(args[1].ToString());
        label1.Text = Convert.ToString(yes + no);
        objreader.Close();
    }
    protected void rdboncheckedchanged(object sender, EventArgs e)
    {
        if (rdbone.Checked)
        {
            getPercentage(0);//yes=0;No=1;
        }
    }
    protected void rdbtwooncheckedchanged(object sender, EventArgs e)
    {
        if (rdbtwo.Checked)
        {
            getPercentage(1);//yes=0;No=1;
        }
    }
 
    public void getPercentage(int value)
    {
        string filename = Server.MapPath("filesave.txt");
        StreamReader objreader = new StreamReader(filename);
        string line = objreader.ReadLine();
        int yes;
        int no;
        string[] args= line.Split('|');
        yes = int.Parse(args[0].ToString());
        no = int.Parse(args[1].ToString());
        double percYes = 0.0;
        double percNo = 0.0;
        if (value == 0)
        {
            yes = yes + 1;
            percYes = 100 * Math.Round((Convert.ToDouble(yes) / Convert.ToDouble((no + yes))), 2);
            percNo = 100 * Math.Round((Convert.ToDouble(no) / Convert.ToDouble((no + yes))), 2);
        }
        else if (value == 1)
        {
            no = no + 1;
            percYes = 100 * Math.Round((Convert.ToDouble(yes) / Convert.ToDouble((no + yes))), 2);
            percNo = 100 * Math.Round((Convert.ToDouble(no) / Convert.ToDouble((no + yes))), 2);
        }
        objreader.Close();
        StreamWriter objWriter = new StreamWriter(filename);
        objWriter.WriteLine(yes + "|" + no);
        objWriter.Close();
        rdbone.Visible = false;
        rdbtwo.Visible = false;
        img1.Visible = true;
        img2.Visible = true;
        label1.Text = Convert.ToString(yes + no);
        img1.Width = Convert.ToInt32(percYes);
        img2.Width = Convert.ToInt32(percNo);
        lbl1.Text = Convert.ToInt32(percYes) + "%";
        lbl2.Text = Convert.ToInt32(percNo) + "%";
    }
}


On .aspx page :

<head runat="server">
<title>Untitled Page</title>
<style type="text/css">
#clsbold
{
font-weight:bold;
font-family:Trebuchet MS
}
</style>
</head>
<body>
    <form id="form1" runat="server">
    <div  id="clsbold">
    <p>Do you like Asp.net??? </p>
    <table>
    <tr>
    <td style="width: 40px; height: 40px;">Yes
    <br /><br />
    No
    </td>
    <td style="width: 13px; text-align:center; height: 40px; ">:
     <br /><br />
     :
    </td>
    <td style="width: 200px; height: 40px;">
     <asp:RadioButton ID="rdbone" GroupName="yesno" runat="server" OnCheckedChanged="rdboncheckedchanged"
AutoPostBack="true"/>
     <img src="poll.gif" alt="" runat="server" id="img1" height="20" visible="false"/>
     <asp:Label ID="lbl1"  runat="server" ></asp:Label>
     <br />
    <br />
    <asp:RadioButton ID="rdbtwo" GroupName="yesno" runat="server" OnCheckedChanged="rdbtwooncheckedchanged"
AutoPostBack="true"/>
      <img src="poll.gif" alt="" runat="server" id="img2" height="18"  visible="false"/>
      <asp:Label ID="lbl2"  runat="server" ></asp:Label>
    </td>
    </tr>
    </table>
    <div style="height:30px; margin-top:10px;">
    Total Poll Votes: <asp:Label runat="server" ID="label1" Text=""></asp:Label>
        </div>
        </div>
    </form>
</body>
</html>