18 August 2016

Difference between GET and POST

Both perform same action only. Using both we can able to transfer data from one application to another. Using get method we can able to view the information in URL itself, but using post we can able to transfer data over networks, so this is very secure. Post method data we can’t get it directly. But Get method data we can get easily.

We can’t able to transfer bulk of data using GET method. But using post method we can able to transfer bulk of data. Compare to GET method POST method is secure.

Self-join queries

Self-Join is a type of join which is used to join the same table by creating the second instance of the same table. So we join 2 instances of the same table in case of self-join. This type of join is used when there is the requirement to get the referenced data which is available in the same table.
e.g. A table contains EmpId, Ename and ManagerId
As the manager id is also an employee id. Now if we want that who is the manager of which employee. In this situation, we need to create the instance of the same table and get the required data as:

SELECT EMPID, ENAME, ENAME AS [MANAGER NAME]
FROM EMP E1, EMP E2
WHERE E1.EMPID= E2.MANAGERID

Anonymous methods in C#

The concept of anonymous method was introduced in C# 2.0. An anonymous method is inline unnamed method in the code. It is created using the delegate keyword and doesn’t required name and return type. Hence we can say, an anonymous method has only body without name, optional parameters and return type. An anonymous method behaves like a regular method and allows us to write inline code in place of explicitly named methods.



A Simple Anonymous Method Example


delegate int MathOp(int a, int b);
class Program
{
//delegate for representing anonymous method
delegate int del(int x, int y);

static void Main(string[] args)
{
//anonymous method using delegate keyword
del d1 = delegate(int x, int y) { return x * y; };

int z1 = d1(2, 3);
Console.WriteLine(z1);
}
}
//output:
6

Key points about anonymous method



  1. A variable, declared outside the anonymous method can be accessed inside the anonymous method.

  2. A variable, declared inside the anonymous method can’t be accessed outside the anonymous method.

  3. We use anonymous method in event handling.

  4. An anonymous method, declared without parenthesis can be assigned to a delegate with any signature.

  5. Unsafe code can’t be accessed within an anonymous method.

  6. An anonymous method can’t access the ref or out parameters of an outer scope.


Anonymous Method as an Event Handler


 <form id="form1" runat="server">
< div align="center">
<h2>Anonymous Method Example</h2>
<br />
<asp:Label ID="lblmsg" runat="server" ForeColor="Green" Font-Bold="true"></asp:Label>
<br /><br />
<asp:Button ID="btnSubmit" runat="server" Text="Submit" />
<asp:Button ID="btnCancel" runat="server" Text="Cancel" />
</div>
</form>


protected void Page_Load(object sender, EventArgs e)
{
// Click Event handler using Regular method
btnCancel.Click += new EventHandler(ClickEvent);
// Click Event handler using Anonymous method
btnSubmit.Click += delegate { lblmsg.Text=
"Submit Button clicked using Anonymous method"; };
}
protected void ClickEvent(object sender, EventArgs e)
{
lblmsg.Text="Cancel Button clicked using Regular method";
}

11 August 2016

Interview questions

http://pawantechit.blogspot.in/2013/03/interview-question-for-3-6-year.html

http://www.interviewquestionspdf.com/2014/09/aspnet-interview-questions-and-answers.html

https://www.udemy.com/understand-nodejs/

https://www.udemy.com/learn-angularjs/

https://www.udemy.com/design-and-develop-a-killer-website-with-html5-and-css3/

User id : aagrawal ksl

Pwd: password234

http://www.dotnetspider.com/resources/44635-Interview-Questions-3-6-years-experienced-Net-professional.aspx

http://www.aspdotnet-suresh.com/2010/05/interview-questions-in-aspnetcnetsql.html

http://pawantechit.blogspot.in/2013/03/interview-question-for-3-6-year.html

http://pluralsight.com/training/Player?author=scott-allen&name=mvc4-building-m2-controllers&mode=live&clip=0&course=mvc4-building

http://www.dotnet-tricks.com/Tutorial/mvclist

08 August 2016

Stored procedure vs inline query

Stored procedures are precompiled and cached so the performance is much better.

The choice of choosing stored procedures will not be performance but it will be more from the aspect of security and maintenance. Below are some of the points where stored procedures are definitely a plus over inline SQL.

Abstraction


By putting all your SQL code into a stored procedure, your application is completely abstracted from the field names, tables names, etc. So when you make changes in the SQL, you have less impact in your C# code.

Security


This is the best part where stored procedures again score, you can assign execution rights on users and roles.



Maintenance ease


Now because we have centralized our stored procedures any issue like fixing defects and other changes can be easily done in a stored procedure and it will be reflected across the installed clients. At least we do not need to compile and deploy DLLs and EXEs.

Centralized tuning


If we know we have a slow running stored procedure, we can isolate it and the DBA guys can performance tune it separately.

Cursors, temp table complications


Simple TSQLs are OK. But what if you have a bunch of statements with IF, ELSE, Cursors, etc? For those kind of scenarios, again stored procedures are very handy.

06 August 2016

State management

A new instance of the Web page class is created each time the page is posted to the server. In traditional Web programming, this would typically mean that all information associated with the page and the controls on the page would be lost with each round trip.

To overcome this inherent limitation of traditional Web programming, ASP.NET includes several options. These features are as follows:

  • View state

  • Control state

  • Hidden fields

  • Cookies

  • Query strings

  • Application state

  • Session state

  • Profile Properties


 

https://msdn.microsoft.com/en-us/library/75x4ha6s.aspx

return types in mvc

Return View

This is a most common and very frequently used type. We see that we can pass eight parameters when we return the view. We can specify the view name explicitly or may not.
Return View

Return partial View

The concept of a partial view is very similar to the master page concept in Web Form applications. The partial view is nothing but  pagelet, that we can return from the controller and that merges with the main view and generates one concrete HTML page.


Return partial View

It may take 4 parameters to render in the partial view.

Redirect

This is equivalent to Response.redirect() or Server.Transfer() functions. It takes the URL path to be redirect , though we can use Response.Redirect() or Server.Transfer() in MVC too.


Redirect

Redirect To Action

Sometimes it is necessary to call another action after completion of one action, this is very similar to a function call in traditional function oriented programming or Object Oriented Programming. It may take 6 parameters. The first parameter is very simple, only action name.


Redirect To Action

Return content

This is useful when we want to return a small amount of strings from a controller/action. It takes three parameters. The first one is a simple string and the remaining two are strings with little information.


Return content

Return JSON

This is very useful when we don't want an entire HTML page but only want a value. Generally in AJAX-based single-page applications we do not load an entire page again and again but load fresh data from the DB using AJAX. In this scenario we can return only a JSON object and in the success function of jQuery ajax (let's assume we are using the jQuery library to implement AJAX) we can just manipulate data.


Return json

Return JavaScript

When we wanted to return a JavaScript string , we may use this function. It takes only one parameter, the string only.


Return JavaScript

Return File

We are allowed to return a binary file if needed from a controller. It takes 6 parameters maximum.


Return File

user control vs custom control in c#


























































Custom ControlUser Control
A loosely coupled control w.r.t code and UIA tightly coupled control w.r.t code and UI
Derives from ControlDerives from UserControl
Defines UI in a ResourceDictionaryDefines UI as normal XAML
UI is skinableChild controls are skinable
Has dynamic layoutHas static layout
UI can be changed in different projectsUI is fixed and can't have different looks in different project
Has full toolbox support, Jst drag n drop from toolboxCan't be added to the toolbox, Jst drag n drop from sol’n explorer to page(aspx)
Defines a single controlDefines a set of controls
More flexibleNot very flexible like a Custom Control
Reusability of control (extend functionality of existing control), Designed so that it can be used by more than one applicationReusability web page, Designed for single-application scenarios
Compiled into dllNot compiled into dll
Creation is similar to the way Web Forms pages are created; well-suited for rapid application development (RAD)Writing involves lots of code because there is no designer support

Button, CheckBox, TextBox etc., even a UserControl is nothing but a Custom Control. You can easily load them inside a XAML page.

Custom Controls are compiled into a DLL assembly and can be reused in multiple places very easily. You have total control over the code, thus gives you more flexibility to extend the behaviour. Once you build and add a reference of the custom control in your project, you can find it in the toolbox. Thus, you will be able to drag and drop the control in your Design view and start working with it very easily.

  • When you have a rapid and fixed content in your UI, use UserControl.

  • When you want to separate some basic functionality of your main view to some smaller pieces with reusability, use UserControl.

  • When you want to use your control in different projects and each project may want to change the look, use CustomControl.

  • When you want to implement some additional functionality for a control, create a CustomControl derived from the base control.

  • When you want to apply themes to your controls, use CustomControl.

  • When you want to add toolbox support for your control, so that your user will be able to do drag and drop to the designer, use CustomControl.


For user control:
<%@ Register TagPrefix="UC" TagName="TestControl" Src="test.ascx" %>

For custom control:

<%@ Register TagPrefix="CC " Namespace=" CustomServerControlsLib " Assembly="CustomServerControlsLib " %>

 

05 August 2016

Linq query on datatable

var results = from myRow in myDataTable.AsEnumerable()
where myRow.Field<int>("RowNo") == 1
select myRow;