Wednesday, October 5, 2011

How to which control effect to post back? ASP.net C#

How to which control effect to post back?
When we developing web base application we want to know which control effect to post back. In here we can do simple approach to find out control which effect to post back.

This is the simple method which can be found out the control. In here we have to pass the page as the parameter. In this example I assume that there are few buttons on my web page and I want to know which button force to post back.

///Method to find out control force to post back.

public static Control GetPostBackControl(Page page)
{
Control control = null;

string ctrlname = page.Request.Params.Get("__EVENTTARGET");
if (ctrlname != null && ctrlname != string.Empty)
{
control = page.FindControl(ctrlname);
}
else
{
foreach (string ctl in page.Request.Form)
{
Control c = page.FindControl(ctl);
if (c is System.Web.UI.WebControls.Button)
{
control = c;
break;
}
}
}
return control;
}

////
Method call
Control _ctlPostback =GetPostBackControl(this.Page);


By using this one you can do what ever thing according to your requirements.
In here i am use switch case to find out control.




if (_ctlPostback != null){
switch(_ctlPostback.ClientID.ToString())
{
#region
case "ctl00_plcContent__butAddRuletoProduct":///your button Client ID...
{
///YOUR CODE....
break;
}
}
}

Monday, May 31, 2010

NHIbernate Simple Windows App

During Pass few weeks I tried to understand about NHibernate. Really when I start doing to understand about NHibernate actually I have not any idea about what is NHibernate is? What power which it has? What can we do with it? So on. I knew only there is some things called NHibernate . I searched and find out some articles tutorials related to that.
NHibernate is Object Relation Mapping (ORM).
With help of simple Windows Form Application I will show easily implement NHibernate base Application.
First it is very important to find out required DLL. You can download those from.

Create Simple Windows Base Application called NHIbernateTestEx1.
Add below DLL to your reference (Simply write click, brows required DLL and add)

  •  NHibernate.dll
  •  Log4net.dll
  •  NHibernate.ByteCode.LinFu.dll

Figure 1 show after Add required DLL.


In this Example tutorial I will use Local Database. Next add local database to Application. Simple write click on the NHibernateTestEx1 and add new item local database and give name it to EmployeeDB.mdf
Figure 2 show local DB.
Now it is time to add App.config file to project. Simply add App.config file and write as bellow. It will do simply configuration with NHibernate.
NOTE THAT : you must add your Data base connection string on

YOUR DATA BASE CONNCTION STRING GOES HERE


Code for App.config file.







NHibernate.Dialect.MsSql2005Dialect

NHibernate.Connection.DriverConnectionProvider


NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu


Data Source=.\SQLEXPRESS;AttachDbFilename=G:\MYExperiment\NHIbernateTestEx1\NHIbernateTestEx1\App_Data\EmployeeDB.mdf;Integrated Security=True;User Instance=True

false

NHibernate.Driver.SqlClientDriver

ReadCommitted
true





Next create class call Employee.cs (This class is come from the Database table which we created. It can be any class related to database table)
Employee.cs
using System;
using System.Collections.Generic;
using System.Text;

namespace NHIbernateTestEx1
{
class Employee
{
private int _sEmpId;
private string _sEmpName;
private string _sEmpAddress;
private string _sEmpContact;

public int EmpId
{
get { return _sEmpId; }
set { _sEmpId = value; }
}
public string EmpName
{
get { return _sEmpName; }
set { _sEmpName = value; }
}
public string EmpAddress
{
get { return _sEmpAddress; }
set { _sEmpAddress = value; }
}
public string EmpContact
{
get { return _sEmpContact; }
set { _sEmpContact = value; }
}
}
}

Next write the Employee.hbm.xml file for simply mapping process. For that create XML file. And add below code to it.
NOTE THAT: class name should be the class which we created in above step. Employee and it belong to NHIbernateTestEx1 namespace (NHIbernateTestEx1.Employee)
In here id tag is for Primary key of Employee table of Database. And others are the rest of columns.












Simply create form like below.

How to create ISession Factory?
Import bellows DLL.
using NHibernate;
using NHibernate.Cfg;
using System.Reflection;
And write below OpenSesion() method. And it will return ISession.
#region ISession Factory
public ISessionFactory _iSessionFactory;

public ISession OpenSession()
{
if (_iSessionFactory == null)
{
Configuration config = new Configuration();
config.AddAssembly(Assembly.GetCallingAssembly());
_iSessionFactory = config.BuildSessionFactory();
}

return _iSessionFactory.OpenSession();
}
#endregion
Insert Method. In this method get user entered data to text boxes and it will insert into Employee database table with the help of OpenSession() and NHibernate.
#region Insert Data NHIBERNATE
public void InsertEmpData()
{
Employee emp = new Employee();
emp.EmpName = textBox_EmpName.Text.ToString();
emp.EmpAddress = textBoxEmpAddress.Text.ToString();
emp.EmpContact = textBoxEmpContact.Text.ToString();

using(ISession session=OpenSession())
{
using(ITransaction transaction=session.BeginTransaction())
{
session.Save(emp);
transaction.Commit();
}
}
}
#endregion
When Insert Button Click it will call to InsertEmpData() method.
private void buttonInsert_Click(object sender, EventArgs e)
{
InsertEmpData();
}

Wednesday, May 19, 2010

IIS Config for ASP web Site

IIS Config...

When we try to browse web sites which published on IIS sometimes it will not be shown in localhost and it will be given some error message by saying try again, XML page can not shown or likewise. Show Figure 1 and 2.




















Figure 1




















Figure 2

Figure 3 shows that the Error Message.









Figure 3

IIWe can fix that problem simply following below step.

Step 1: Goto Start----> Run
and type cmd












Step 2: now you can we see CMD.
on it goto C:\ (to root by cd.. xxxx)

And goto C:\Windows\Microsoft.NET\Framwork\v2.0.50727\aspnet_regiis.exe

And next should uninstall by typing -u

C:\Windows\Microsoft.NET\Framwork\v2.0.50727\aspnet_regiis.exe -U
Figure 5 show that how to follow 2 step











Figure 5

After uninstaled it looks like figure 6











Figure 6

Step 3: Now install again

C:\Windows\Microsoft.NET\Framwork\v2.0.50727\aspnet_regiis.exe

And next should uninstall by typing -i

C:\Windows\Microsoft.NET\Framwork\v2.0.50727\aspnet_regiis.exe -i
Figure 7 show that Step 3












Figure 7

Step 4: Now follow bellow step.
C:\Windows\Microsoft.NET\Framwork\v2.0.50727\aspnet_regiis.exe -r
show figure 8 and figure 9










Figure 8










Figure 9


Now error is fixed. now you can browse web site.

Friday, November 20, 2009

How to Activate Kaspersky antivirus Trail Version.

Kaspersky Antivirus is a one of the best Antivirus. But it is issue free licence therefor we can use only Kaspersky antivirus trail vision. If we found some licence key related to that it also back listed with short period time. Therefor it is very huge headache for us for who use Kaspersky Antivirus trail version.


But there is some solution for that. We can use Kaspersky Antivirus without original licence key.

Follow below simply step.

To start step it is import to check whether you have already installed Kaspersky 2009 . If you already have not install Kasperskey download. And installe.

http://www.mediafire.com/?sharekey=9cf1fd10916b4282d5a101cf914073b4f157a242d7e9bf1a

Now I assuem you already installed Kasperskey 2009.

On Kaspsky Icon right click and it will pop up window like Figure 1.














Figure 1

On that select “Setting” now it will pop up window like Figure 2.


















Figure 2

On that window Goto Option Check Figure 3.

















Figure 3

Now it is very important to uncheck the Self Defence. And Apply changes. Check Figure 4.

















Figure 4

Now goto Kaspersky Icon on bar and Rigth click and Exit like Figure 5.














Figure 5

Now here after we want application called Kaspersky Trail Reset. If you have not that download that one.

http://www.mediafire.com/?jjnemjxdztj


It contain basically 5 files. According to your PC you can selcet Kaspersky Trail Reseter according to your PC. Figure 6 shows that 5 fills. In here I am use Win32 file. After select trail reseter according to your Pc run it.














Figure 6

If you have not disable Self-Defense it will pop up window like Figure 7. If you have already disable Self-Defense it will not be poped up. (check Figure 1,2,3 if you not disable Self-Defense )








Figure 7

After installing success it will be given alert like Figure 8.









Figure 8

Now your can activate Trial Version using your internet connection. It will be valid 30 days.


















Figure 9

















Figure 10

After succsing all above step now you can finish process. Check Figure 11.

















Figure 11

Now you have activated Kasperskey for 30 days. And after 30 days you can do same process from step by step can activate again and again.During trail period you can do lot of actions with Kaspersky. It will be huge benefit for users who use Kaspersky trail version.

Saturday, October 31, 2009

CREATE 2D GAME YOURSELF TUTORIAL 1

After successfully installing Visual Studio .net and Microsoft XNA Game Studio, we can start to create Window base game or XBOX360 base game our self.


1st step:

All programs-> Microsoft XNA Game Studio

After open XNA Game studio go to
File->New->Project or (ctr+shift+N)
Now it selects XNA Game Studio under Visual C#. And select Windows Game check figure 1.














Figure 1 show that selects Windows Game.

In here you should provide the name for the game which going to create and should provide the location to save the project after that press OK button.
2nd step:
Now you can see Solution Explorer. Check Figure 2.


















Figure 2

Now it is better to know about the Game.cs file. By clicking on that you can see it has basically Five methods already. Now on here we can create game using that already created methods.

1) Initialize() -(Provide Game initial information)
2) LoadContent()- (Using that load resource files such as images,videos,sound files,font and so on)
3) UnloadContent()-(Using that we can unload resource which we load using LoadContent() method)
4) Update(GameTime gameTime) –(use to update action are goes here)
5) Draw(GameTime gameTime) – (Use to draw resource which we added)
Now I think you have some idea about how the game create procedure is going. Let’s check how to add image to our Game project.
How to add image to Game Project

Before you can start drawing backgrounds, characters, or so on having in your game to the screen, you will need to add these images to your game project. The image types you can add that are supported by the Content Pipeline are .bmp, .jpg, .png and a few texture file formats. Adding the images to your project makes them available to the XNA framework's Content Importer. This will compile them as ".xnb" files when you build your game and make them accessible to the Content Importer in the code for loading and unloading.

3rd step:

To add image to game project, Right click on Content and should provide existing items. Check figure 3.



















Figure 3.

Now you can brows and able to provide image to your game project. After providing image path now you can see the image which you added is added to Content Pipeline. Check Figure 4.











Figure 4

Now you have added image. And next go to Game.cs and should provide added images reference. For that should use Texture2D mickymouse2D;

Next using above added reference we must load that image to our game project for that go to LoadContent() methods and add following line mickymouse2D = Content.Load("Mickymouse"); in here “Mickymouse” is the image name which I alredy added to Content Pipe. Now I have already loaded image to my game. Now my next step is draw that load image on my screen. To do that I must use Draw(GameTime gameTime) method. And add following few line on it.

Rectangle mickymouse2DPosition = new Rectangle(100, 100, 100, 100);
spriteBatch.Begin(SpriteBlendMode.AlphaBlend);
spriteBatch.Draw(mickymouse2D, mickymouse2DPosition, Color.White);
spriteBatch.End();
base.Draw(gameTime);

in here I provide the position which my image should draw. Now press play button and you can see the image is drawn on your game screen. Check figure 5.















Figure 5

Lets check complete source code.

using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace MyGame1
{
public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
Texture2D mickymouse2D;

public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}

protected override void Initialize()
{
base.Initialize();
}

protected override void LoadContent()
{
spriteBatch = new SpriteBatch(GraphicsDevice);
mickymouse2D = Content.Load("Mickymouse");
}
protected override void UnloadContent()
{
// TODO: Unload any non ContentManager content here
}

protected override void Update(GameTime gameTime)
{
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
base.Update(gameTime);
}

protected override void Draw(GameTime gameTime)
{
graphics.GraphicsDevice.Clear(Color.CornflowerBlue);
Rectangle mickymouse2DPosition = new Rectangle(100, 100, 100, 100);
spriteBatch.Begin(SpriteBlendMode.AlphaBlend);
spriteBatch.Draw(mickymouse2D, mickymouse2DPosition, Color.White);
spriteBatch.End();
base.Draw(gameTime);
}
}
}

Now you can add image to your games screen.

Your Comments are highly appreciated; it will be improving my knowledge also.

Saturday, October 24, 2009

Create SQL Maintenance Plan in SQL Server Management Studio (SSMS)

SQL Maintenance Plan plays huge role in SQL Server. Therefore I am going to explain step by step how to create SQL Maintenance Plan. Using that you can do lots of plan simultaneously.

1st Step:
Flow below path to create SQL Maintenance Plan.
After login to SSMS go to
Management-> Maintenance Plan -> Maintenance Plan Wizard
Figure 1 shows that how to start Maintenance Plan.


















Figure 1

It will popup window like Figure 2.


















Figure 2

Press next.

2nd Step
After following 1st step it will be pop up window like Figure 3.

















Figure 3

In here can provide Name for the Maintenance Plan, description for the Maintenance plans which going to create. It will provide to select Server. And according to that can logging using Windows Authentication or SQL Server Authentication. Press Next button and it will be pop up window like Figure 4.

















Figure 4

3rd Step
It asks what the plans are. According to your requirements you can provide plans which want to create. Can be check on check box which wants to create Maintenance Plan. In here I checked some plans (Figure 4) which I want to make Maintenance Plan likewise you can select whatever plans. Click on next button.

4th Step
After following above step it will be popup new window like Figure 5. Using that window can be move up down selected plans. Click on next button.

















Figure 5
Next it will be popup window like Figure 6. And using that can be provide validity to database it means that what are the data base that create Maintenance Plan belong.

5th Step
Next according to 2nd step which selected plans one by one SSMS provide window and you can provide database which you want to make plan.
Figure 6 show that According to Check Database Integrity Task.

















Figure 6

  • Figure 7 show that According to Shrink Database Task.



















Figure 7

  • Figure 8 show that According to Rebuild Index Task.

















Figure 8

  • Figure 9 shows that Update Statistics Task.



















Figure 9

  • Figure 10 shows Cleanup History Task


















Figure 10
  • Figure 11 shows that how to create Backup


















Figure 11

  • Now all my schedule plans were finish and it will be pop up new window like Figure 12.



















Figure 12

  • Now you can change and create new Job schedule by pressing Change button. And it will be popup window like Figure 13.

















Figure 13
  • By pressing next it will be popup new window and next it will be process and create Maintenance Plan according to your requirements.

Your Comments are highly appreciated; it will be improving my knowledge also.

Friday, October 23, 2009

HOW TO GET SQL BACK UP

When we dealing with SQL server it is very import to get the SQL Back up because some time we want back up to resort data base if data base corrupt or loosing data. Basically SQL provide facilities to get back up.
Following below step you can get easily SQL back ups

Select whatever database which wants to get back up. And right click.

Task--> Back Up…..
















Figure 1 shows that the pop up window.

1) By drop downing can select back up type. (Full, Differential, Transaction Log). In here select Full option from Backup combo box.
2) Provide Suitable name and description for backup which are going to take.
3) Back up set Expire. Inhere able to provide particular day or days to expire the backups. It will defend on user requirements.
4) By pressing Add button able to add new store folder to the back. Likewise we can add more physical location for our back up. Like wise we can remove store location by pressing Remove.

By pressing ok can get SQL backup easily.









Figure 2 show that the backup which created.


As well as following above steps we all so can do same process using SQL Query.
Open Query editor
And enter code like below.

BACKUP DATABASE [Name of Database] TO
DISK =N'Backup save path\backupname.bak’
WITH NOFORMAT, NOINIT,
NAME =N'DESCRIPTION OF BACK UP',
SKIP, NOREWIND, NOUNLOAD, STATS=10
GO

By executing above query can get backup also.














Figure 3 shows that example code.







About This Blog

  © Blogger templates 'Neuronic' by Ourblogtemplates.com 2008

Back to TOP