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