C# : Tutorial of Asp.net with c# and example

Example and code about windows application, web application, SQL, C#, WPF etc which is helpful to developer and programer.

Search This Blog

UserControl Tutorial : Create ,Register and use of usercontrol in asp.net with example and code

♠ Posted by Unknown in ,



Tutorial Of Asp.Net UserControl


Definition of UserControl in Asp.Net :

In Asp.Net Web server controls , you can create your own custom, reusable controls using following step. These controls are called user controls.

A user control is a kind of composite control that works much like an ASP.NET other server control . you can add existing Web server controls and markup to a user control, and define properties and methods for the control. You can then embed them in ASP.NET Web pages like same as other server control.



For create asp.net usercontrol using c# following step perform





Step 1: First of all add one folder in your website or project for contain all user control as follow screen.

Step 2:Right Click on folder in which you want to contain usercontrol as follow screen.

Step 3: Select web user control , give proper name and click to add button as follow screen



Step 4 : after add you can see your control in your project or website as follow screen:


Step 5: Now you need to add code in .ascx page as per your required control as follow screen:

Code For Simple Text box control make as userdefine control you set property once in user define control then you no need to write again only need to register control on your page and use it. Following code in .ascx page.

<asp:TextBox ID="TextBox1" runat="server" BackColor="WhiteSmoke" BorderColor="ActiveBorder"
    Font-Bold="true" Font-Size="X-Large" ForeColor="Aqua" Height="70px" TextMode="MultiLine" runat="server"
    Width="100px"></asp:TextBox>
Now your control is ready to use.

Step 6: Add following code to register user control in your webpage in second line:


<%@ Register Src="~/Control/UserDefineTextBoxWebUserControl.ascx" TagName="TextBox" TagPrefix="My" %>

Step 6: Now code for use control in your page at content as follow:

<My:TextBox ID="mytextbox1" runat="server" />

See here no need to set any property and you get output as follow:


This way you can make any server control to your own control such as linkbutton, Dropdown, checkbox, radiobutton, etc.


Improve Your Answer as comment below.
If our post is useful please share and comment on our post for more post and detail Visit :

http://aspdotnethelpmaster.blogspot.in/

How to create database using

♠ Posted by uvesh in

Create Database by programmatically


 protected void CreatDbBtn_Click(object sender, EventArgs e)
    {
        String str;
        SqlConnection myConn = new SqlConnection(@"Server=HOME\SQLEXPRESS;Integrated security=SSPI;database=master");
        str = "CREATE DATABASE MyDatabase ON PRIMARY " +
            "(NAME = MyDatabase_Data, " +
            "FILENAME = 'D:\\UveshMyDatabaseData.mdf', " +
            "SIZE = 2MB, MAXSIZE = 10MB, FILEGROWTH = 10%) " +
            "LOG ON (NAME = MyDatabase_Log, " +
            "FILENAME = 'D:\\MyDatabaseLog.ldf', " +
            "SIZE = 1MB, " +
            "MAXSIZE = 5MB, " +
            "FILEGROWTH = 10%)";

        SqlCommand myCommand = new SqlCommand(str, myConn);
        try
        {
            myConn.Open();
            myCommand.ExecuteNonQuery();
            Response.Write("DataBase is Created Successfully");

            //MessageBox.Show("DataBase is Created Successfully", "MyProgram", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
        catch (System.Exception ex)
        {
            Response.Write(ex.ToString());
            //MessageBox.Show(ex.ToString(), "MyProgram", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
        finally
        {
            if (myConn.State == ConnectionState.Open)
            {
                myConn.Close();
            }
        }

    }

Improve Your Answer as comment below.

If our post is useful please share and comment on our post for more post and detail Visit :


http://aspdotnethelpmaster.blogspot.in/

Web Service Definition and when it is use and not to use


What is web service and its use.

Web services 
The Definition Web Service A web service is any part of software that makes available over the network and uses a XML (Full form of XML is Extensible Markup Language (XML) is a markup language in a format which is both human-readable and machine-readable.) format messaging system. XML is used to encode all communications to a web service. Any application which has permission to access service can use service from anywhere. It is platform independent. 

(sometimes called application services) are services (usually including some combination of programming and data, but possibly including human resources as well) that are made available from a business's Web server for Web users or other Web-connected programs. Providers of Web services are generally known as application service providers.

It is based information send-Receive systems that use the by Internet for application (software)-to-application (software) communication. This application can include objects, messages, or documents.

Use Of Web Service

It is system software. Specially design for support machine-to-machine interaction over a local network internet. The basic services supported platform is XML and HTTP or HTTPS. XML can be used between different platforms and programming languages and complex messages and functions. It is help to solve interchangeability by giving your applications a way to integrate their data. For Example your one website is online and you also want to make its android application. That time you need web service so you’re both application work synchronously. You require this because user sometime work on website and some time also use mobile application like android app then user want synchronized own data. For that developer use same service for both platform website application and android application so no need to work for both platforms. 

When Not Use Web Service

when your application no need to synchronize and when more application use only single service because of that more load on server.mostly when service use for operation on database that time overload problem occurs so when number of application use web service which is ping db its problematic to database overhead.

so for database you need to make multiple version of web service so its useful to maintain database overhead.


If our article useful or like to you please share our post.for more detail visit About Web service

Code For do connection with ms access data base and explain concept with example and connection string using oledb connection.



In This Article we explain about Data Base Connection with MS Access Data Base 2007


Use Of Data Base connection: 
Data base connection is use for retrieve, insert, update, delete data from database by any system or software.


Following step for establish connection with Ms Access Data Base 2007
Step 1- Put following code in web.config file of asp.Net website

  
<connectionStrings>
    <add name="myconnectionstring" providerName="System.Data.OleDb" connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=E:\DB\Database1.accdb"/>
  </connectionStrings>

Step 2- Import Following two package in your code Behind (.aspx.cs) file where you want to do connection

using System.Data.OleDb;
using System.Configuration;

Step 3- We Do connection on load of page so put following code Page_load Event code Behind (.aspx.cs) file where you want to do connection.

OleDbConnection conn = new OleDbConnection(ConfigurationManager.ConnectionStrings["myconnectionstring"].ConnectionString);
        try
        {
            conn.Open();
            msglitrl.Visible = true;
            msglitrl.Text = "Connection Done Successfully";
        }
        catch
        {

            msglitrl.Visible = true;
            msglitrl.Text = "Connection Fail.";
  }

Summary:

In Web.Config file

<connectionStrings>
    <add name="myconnectionstring" providerName="System.Data.OleDb" connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=E:\DB\Database1.accdb"/>
  </connectionStrings>

In code behind file

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OleDb;
using System.Configuration;
public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        OleDbConnection conn = new OleDbConnection(ConfigurationManager.ConnectionStrings["myconnectionstring"].ConnectionString);
        try
        {
            conn.Open();
            msglitrl.Visible = true;
            msglitrl.Text = "Connection Done Successfully";
        }
        catch
        {

            msglitrl.Visible = true;
            msglitrl.Text = "Connection Fail.";
        }
   }


In ASP.net open window form as popup box with example

♠ Posted by Unknown

How To Open second window form as popup on first window form in Asp.Net

You can create popup window of window form in asp.net or vb.net windows application it is use full to take input from user or give hint information etc. You need use following step for open window form as popup window  :

Step 1: Create one form in window application name mainform.

Step 2 : Create second form in window application give name popupform.

Step 3 : Create any one event, on which particular event you want to open popup window.

Example of event: button Onclick, Mouse Click,etc

Step 4: in particular event write following code:

In code  behind of mainform :

import 

using WindowsFormsApplication1;

in particular event :

new popupform().showDialog();



If You like our blog please share it and comment on it. Visit again.

http://aspdotnethelpmaster.blogspot.in/



Asp.Net: How to make Button make as default button in asp.net?

♠ Posted by uvesh in



How to make button as default button?

 
Your Button put in panel and give button id in DefaultButton property of panel. most of people think and find Button's property to make it default but actually here asp panel is require and set panel's property DefaultButtton="Here write button id which you want to make default"  .


<asp:Panel ID="pnl1" runat="server" DefaultButton ="Button1">
  <asp:Button ID="Button1" runat="server" text="Click Me!" />
   <asp:Button ID="Button2" runat="server" text="PushMe" />
</asp:Panel>


Here  your default button is  Button1
Using this functionality no need to click by button just enter and click event of default button is occures.

Here other property of button control is text which text you can see on button like as below image :



 

Improve Your Answer as comment below.
If our post is useful please share and comment on our post for more post and detail Visit :

http://aspdotnethelpmaster.blogspot.in/

 

SQL: 'IN' Query example in SQL with c#

♠ Posted by uvesh in


Example of 'in Query' in SQL Server Management studio 2008 with C#

Whenever you fire where condition in SQL you need give some value in where condition some time you need to only assign only single value or some times you need to assign number of value in where condition that time IN Query is most useful. 

there may be in database comma sepreted  value in single field and you need to right in Where condition that time IN Query is most useful to you.

For Example In below code First make one string using foreach loop from datatable which is comma sepreted and ten last statement contain SQL Query which contain Where condition. 

here Where condition on empid field which compare number of empid at a time which is comma sepreted.


string var = "";
foreach (DataRow row in table.Rows)
{
var += row["emp_no"].ToString() + ",";
}
if (var.EndsWith(","))
{
var = var.Trim().Substring(0, var.Trim().Length - 1);
//do sql connection
string value1 = sql.GetSingleValue("select empuniqid from Empmaster where empid in ( " + var + " ) ");



Improve Your Answer as comment below.
If our post is useful please share and comment on our post for more post and detail Visit :

http://aspdotnethelpmaster.blogspot.in/