Category C#.Net

Difference between Authorization and Authentication

Category: C#.Net Comments: No comments

Authentication Authorization Authentication verifies who you are Authorization verifies what you are authorized to do Authenticating a user on a website means that you verify that this user is a valid user, that is, verifying who the user is using username/password or certificates, etc Authorization is the process of verifying if the user has rights/permission to access certain resources or sections of a website, Example : When u login to access some site then your logon credential (userid/password) identifies Example : After successful logon, you will be granted specific role or privileges to access the site.Read More

Difference between Destructor, dispose and finalize method

Category: C#.Net Comments: No comments

Destructor They are special methods that contains clean up code for the object. You can’t call them explicitly in your code as they are called implicitly by GC (Garbage Collector). In C# they have same name as the class name preceded by the "~" sign. Like- class MyClass { public MyClass () { } ~MyClass () { } } Dispose These are just like any other methods in the class and can be called explicitly but they have a special purpose of cleaning up the object. In the dispose method we write clean up code for the object. It is important that we freed up all the unmanaged resources in the dispose method like database connection, files etc. The class implementing dispose method should implement IDisposable which is inherited by interface and it contains GC.SuppressFinalize method for the object it is disposing if the class has destructor because it has already done the work to clean up the object, then it is not necessary for the garbage collector to call the object's Finalize method.Read More

Use of ViewState in Asp.net

Category: ASP.NETC#.Net Comments: No comments

ViewState is used to maintain the state of controls during page postback and if we save any control values or anything in viewstate we can access those values throughout the page whenever it required for that check below simple example
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head runat=”server”>
<title>View State in asp.net Example</title>
</head>
<body>
<form id=”form1″ runat=”server”>
<div>
<table>
<tr>
<td>ViewState Data:</td><td><b><asp:Label ID=”lblString” runat=”server”/></b></td>
</tr>
<tr><td></td><td> <asp:Button ID=”btnClick” runat=”server” Text=”Get ViewState Data”
onclick=”btnClick_Click”/></td></tr>
</table>
</div>
</form>
</body>
</html>
Now add following namespaces in your codebehind

C# Code
using System;

After that write the following code in button click
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
string str = “Welcome to Dotnettricks-Abdul”;
if(ViewState["SampleText"]==null)
{
ViewState["SampleText"] = str;
}
}
}

protected void btnClick_Click(object sender, EventArgs e)
{
lblString.Text = ViewState["SampleText"].ToString();
}

Read More

Show Alert Box From Serverside in Asp.net

Category: ASP.NETC#.Net Comments: No comments

Show Alert Box From Serverside in Asp.net

//Fuction for Alert Box

protected void jsCall(string alertmessage)
{

string script = @”alert( “”" + alertmessage+ @”"” );”;
ScriptManager.RegisterStartupScript(this, this.GetType(), “jsCall”, script, true);
}
//Call “jsCall” Function with message where u want.

jsCall(“Alert successfully.”);

Read More

Use of UrlEncode and UrlDecode Method in Asp.net

Category: ASP.NETC#.Net Comments: No comments

Use of UrlEncode and UrlDecode Method in Asp.net

UrlEncode Method :

HttpUtility.UrlEncode(string)
Ex:
string encodedText= HttpUtility.UrlEncode(txtrefcode.Text.Trim())
string url = “Test.aspx?enc=” + encodedText;
Response.Redirect(url);

UrlDecode Method :

HttpUtility.UrlDecode(Encoded String);
Ex:
string decodeValue = HttpUtility.UrlDecode(Request.QueryString["enc"]);

Read More

3-Tier Architecture in asp.net using C# with Crude Operations

Category: ASP.NETC#.NetTHREE TIER ARCHITECTURE Comments: 7 comments

3-Tier Architecture in asp.net using c# 3-Tier architecture consists of 1) UI or Presentation Layer 2) Business Access Layer or Business Logic Layer 3) Data Access Layer Presentation Layer Presentation layer consists of pages like .aspx or desktop based form where data is presented to users or getting input from users. Business Logic layer or Business Access Layer Business logic layer contains all of the business logic. Its responsibility is to validate the business rules of the component and communicating with the Data Access Layer. Business Logic Layer is the class in which we write functions that get data from Presentation Layer and send that data to database through Data Access Layer.Read More

Dynamic Data Manipulation using XSLT using c# methods

Category: ASP.NETC#.NetXSLT Comments: No comments

If you want to display dynamic data/from database in xslt then this is a way to do your requirements. In this we are directly firing a query which returns data in xml format then according to the node names u can transform your xslt. Step 1: Create a xslt named as Sample.xsl < ?xml version="1.0" encoding="UTF-8" ?>
Category name :
Details on Category :
Read More

How to apply an XSLT Stylesheet in C#

Category: ASP.NETC#.NetXSLT Comments: No comments

The main purpose to use XSLT in C# for making your application faster while rendering from server. this is the following code on how to use simple xslt files in ur aspx page by using c#. This is only for rendering a static data only not dynamic means the xslt contains hard coded data only. This can be handy when u r using any header or footer or any portion of your application which is a bit heavier and taking more time to load. Step 1: Create a file named as Demo.xsl and put the below code. < ?xml version="1.0" encoding="UTF-8" ?>
Test xslt page
Demo text here
Read More

How to call C# Method from Java Script

Category: ASP.NETC#.Net Comments: No comments

If you want to call any method of cs page from JS then this is the best way that you can follow. This is required when ur buttons onClick event are not fired den u can call the onClientClick of button and then call the required method. Step 1: Create any page lets say Default.aspx. With in the body part look carefullyRead More

Function for Remove Html Tags using C# in Asp.net

Category: ASP.NETC#.Net Comments: No comments

Pass string Message in ob public string RemoveHTML(string ob) { string str = string.Empty; string splitText = string.Empty; str = Regex.Replace(ob, @"< [^>]*>", "", RegexOptions.Compiled); if (str.Length > 100) { splitText = Server.HtmlDecode(str.Substring(0, 100) + "...");Read More