Saturday, May 19, 2012

How to use Multiview in asp.net

Multi view is a such asp.net intrinsic control and it is collection of views.A multi view can not have any control.A multi view can have view multi view by default not show any view. multi view can display only single view.All views can share the content declared in the page because they all belong to single page only

Here i will show how to use by placing 3 buttons/link buttons and multi view in the page.Then place the views inside the multi view control and place required controls inside views
protected void buttin1_click()
{
MultiView1.ActiveViewIndex =0;
}
protected void buttin2_click()
{
MultiView1.ActiveViewIndex =1;
}
protected void buttin3_click()
{
MultiView1.ActiveViewIndex =2;

Friday, May 18, 2012

How to use view state in asp.net

View state provides page level state management i:e as long as user is in current page state is maintained,as redirected to new page the current page state is lost  and new page state is started .view state can store any type of data   .It is not preferred to store complex type of data as it has to undergo serialization and serialisation every time
View state data is not secured it is simply encoded in  base64 format and because of which is not readable.Any how view state related configuration settings and some properties are available to make the data encrypt/secured
-->View state falls in client state management because no load or values are stored with server
//button_click event
{if(Viewstate["dsdata"]==null)
{
ds=DataHelper.GetData("elect*from emp");
Viewstate["dsdata"]=ds;
}
else
{
ds=(Dataset)Viewstate["dsdata"];
ds=DataHelper.GetData("elect*from emp");
Viewstaae["dsdata"]=ds;
}
GV.DataSource=ds.Table[0];
Gv.DataBind()
}

Thursday, May 17, 2012

Passport authentication in asp.net

This is third party authentication method.In this method we ask users to get authentication from Microsoft third party Service oriented website that is passport.com(live.com)The following steps are perform during passport authentication
1.user makes a request to secured web page
2.IIS allowed user as anonymous
3.Asp.net checks for passport identity and redirects the user to passport website
4.passport displays login page where user should enter passport registered details
5.passport checks for credentials and creates an identity called passport ticket. This ticket is redirected to user
6.user along with ticket requests secured page and is allowed as anonymous and this time asp.net also allowed because of passport identity

Wednesday, May 16, 2012

how to execute sql query in c sharp

Here i will show how to Excute the sql query in sql server using c#. For this I will use one method with two parameters which are database connection string and file name.Then read the text in file and passed to string array.Finally we will execute the query using sqlcommand

public void executeSqlfileincsharp(string connectionStringName, string executesqlFileName)
  {
string sqlConnectionString = ConfigurationManager.ConnectionStrings[connectionStringName].ToString();
FileInfo file = new FileInfo(executesqlFileName);
string sqlString = file.OpenText().ReadToEnd();
using (SqlConnection mySqlConnection = new SqlConnection(sqlConnectionString))
{
string[] spliter = { Environment.NewLine, " GO ", Environment.NewLine };
string[] sqlArrayString = sqlString.Split(spliter, StringSplitOptions.RemoveEmptyEntries);
string executeString = "";
for (int i = 0; i < sqlArrayString.Length; i++)
    {
  executeString = executeString + " " + sqlArrayString[i].ToString();
 }
using (SqlCommand mySqlCommand = mySqlConnection.CreateCommand())
{
 mySqlCommand.CommandText = executeString;
 mySqlConnection.Open();
 mySqlCommand.ExecuteNonQuery();
}
}
}

Tuesday, May 15, 2012

What is a partial class and how to use in c sharp

It was introduced under 2.0 framework which allows you to split a class o n to multiple files
Advantages:
Splitting huge volumes of code into multiple files which makes managing easier.Allows multiple programmers to work on the same class at the same time.grouping related code of a class in separate files
Here i will show how to develop a partial class in csharp.For this add a class to the project naming it as File1.cs and write the following code
partial class parts
{
public void test1()
{
Console.Writeline("method1");
}
public void test2()
{
Console.Writeline("method2");
}
}
add one more class naming it as File2.cs
 partial class parts { public void test3() { Console.Writeline("method3"); } public void test4() { Console.Writeline("method4"); } } Now to test the class add one more class to the project naming it as test parts.cs and write the following class testparts { static void main() { parts p= new parts(); p.test1(); p.test2(); p.test3(); p.test4(); Console.ReadLine();
} }

Bel