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

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/

ASP.Net: How to use ajax calender extender control with demo code in C#

♠ Posted by uvesh in

ASP.NET AJAX Calender Extender use for the get selected date in particular control like textbox,Image button or button.


Step 1: First of all you need download ajax control toolkit from http://ajaxcontroltoolkit.codeplex.com/ and add in your project Bin Folder by right click on Bin  Folder And select add reference.
then add following code in web.config file of asp.net project or website:
<pages>
      <controls>
                <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add tagprifix="ajaxToolkit" namespace="AjaxControlToolkit" assembly="AjaxControlToolkit"/>
      </controls>
    </pages>
OR
You can add it on page like as follow:
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
Step 2: Add ToolScriptManager as follow:


<ajaxToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</ajaxToolkit:ToolkitScriptManager>

Step 2:  Add One text box on your page as follow:
<asp:TextBox ID="txtDate" runat="server" ReadOnly="true"></asp:TextBox>
 
Step 3: Add One Image Button on your page as follow:

<asp:ImageButton ID="imgPopup" ImageUrl="images/calendar.png" ImageAlign="Bottom"
    runat="server" />
 
Step 4:  Now add Ajax calendarextender tag as follow:
   
<ajaxToolkit:CalendarExtender ID="Calendar1" PopupButtonID="imgPopup" runat="server" TargetControlID="txtDate"
    Format="dd/MM/yyyy">
</ajaxToolkit:CalendarExtender>

OutPut As Follwo:















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 use ispostback proerty in asp.net with example

♠ Posted by uvesh in

Use of IsPostBack property and its example


It is not method.
It is the property in the System.Web.UI namespace.
It should be Page.IsPostBack.

IsPostback property is used to Gets a value that indicates whether the page is being rendered for the first time or is being loaded in response to a postback.

This IsPostBack property returns the boolean value either True or False.

The following example shows how to test the value of the IsPostBack property when the page is loaded
in order to determine whether the page is being rendered for the first time or is responding to a postback.
If the page is being rendered for the first time, the code calls the  excuteonpageload() method.

private void Page_Load()
{
    if (!IsPostBack)
    {
        // Validate initially to force asterisks
        // to appear before the first roundtrip.
        excuteonpageload();
    }
}

After render the web page, if you do any post back then it will be called. In the web page,
we used to check whether its loaded first time or posted back.
Because we do not want to bind the concrete controls to rebind again.
It will increase the performance of the web application.



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/

use of Gridview control in asp.net and example of gridview

♠ Posted by uvesh in


What is gridview conntrol in asp.net and its use ?

  • gridview is a very useful control in asp.net. 
  • gridview is mainly uses for display data in tabularform.
  • it also can edit, update, insert data. 
  • this can help you to display and format tabular data very easy and fastest way.
  •  we can format the gridview's nearly all parts as example header, row, alternate row, paging etc. 
  • even we can place insert,edit,delete button for each row. 

Example of Grid view control using .aspx page in asp.net as follow:


In this simple example we create a default formatted gridview. we also create a sqldatasource control populate the data source by a simple database query.


<script runat="server">  
  
</script>  
  
<body>  
    <form id="form1" runat="server">  
    <div>  
      
        <asp:GridView ID="GridView" runat="server" AllowPaging="True"   
            AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="ClientId"   
            DataSourceID="SqlDataSource_demo">  
            <Columns>  
                <asp:BoundField DataField="ClientId" HeaderText="ClientId" ReadOnly="True"   
                    SortExpression="ClientId" />  
                <asp:BoundField DataField="CompanyName" HeaderText="CompanyName"   
                    SortExpression="CompanyName" />  
                <asp:BoundField DataField="ContactName" HeaderText="ContactName"   
                    SortExpression="ContactName" />  
                
                <asp:BoundField DataField="Address" HeaderText="Address"   
                    SortExpression="Address" />  
                <asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />  
              <asp:BoundField DataField="PinCode" HeaderText="PinCode"   
                    SortExpression="PinCode" />
<asp:BoundField DataField="State" HeaderText="State"   
                    SortExpression="State" />    
                <asp:BoundField DataField="Country" HeaderText="Country"   
                    SortExpression="Country" />  
                <asp:BoundField DataField="Moble" HeaderText="Moble" SortExpression="Moble" />
                <asp:BoundField DataField="Landline" HeaderText="Landline" SortExpression="Landline" />  
            </Columns>  
        </asp:GridView>  
        <asp:SqlDataSource ID="SqlDataSource_demo" runat="server"   
            ConnectionString="<%$ ConnectionStrings:AppConnectionString1 %>"   
            SelectCommand="SELECT * FROM [Client]"></asp:SqlDataSource>  
      
    </div>  
    </form>  
</body>  
</html>




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/

List of event in page life cycle of asp.net

♠ Posted by uvesh in


Page life cycle of asp.net




A list of events in the ASP.NET page life cycle.



1. PreInit:

Check for the IsPostBack property to determine whether this is the first time the page is being processed.
Create dynamic controls.
or reCreate dynamic controls.
Set master page dynamically.
Set the Theme property dynamically.
Read profile property values.
Set profile property values.

If Request is postback:

The values of the controls have not yet been restored from view state.
If you set control property at this stage, its value might be overwritten in the next event.

2. Init:

In the Init event of the individual controls occurs first, later the Init event of the Page takes place.
This event is used to initialize control properties.

3. InitComplete:

Tracking of the ViewState is turned on in this event.
Any changes made to the ViewState in this event are persisted even after the next postback.
PreLoad:

This event processes the postback data that is included with the request.

4. Load:

In this event the Page object calls the OnLoad method on the Page object itself, later the OnLoad method of the controls is called.
Thus Load event of the individual controls occurs after the Load event of the page.

5. ControlEvents:

This event is used to handle specific control events such as a Button control’s Click event or a TextBox control’s TextChanged event.
In case of postback:

If the page contains validator controls, the Page.IsValid property and the validation of the controls takes place before the firing of individual control events.
LoadComplete:

This event occurs after the event handling stage.
This event is used for tasks such as loading all other controls on the page.

6. PreRender:

In this event the PreRender event of the page is called first and later for the child control.
Usage:

This method is used to make final changes to the controls on the page like assigning the DataSourceId and calling the DataBind method.

7. PreRenderComplete:

This event is raised after each control's PreRender property is completed.

8. SaveStateComplete:

This is raised after the control state and view state have been saved for the page and for all controls.

9. RenderComplete:

The page object calls this method on each control which is present on the page.
This method writes the control’s markup to send it to the browser.

10. Unload:

This event is raised for each control and then for the Page object.

11. Usage:

Use this event in controls for final cleanup work, such as closing open database connections, closing open files, 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/

Concept of MVC (Model View Controller) in asp.net

♠ Posted by uvesh in

Definition of MVC(Model View Controller) in asp.net



MVC is one of three ASP.NET programming models. MVC is a framework for building web applications using a MVC (Model View Controller) design: The Model represents the application core (for instance a list of database records).

ASP.NET MVC gives you a powerful, patterns-based way to build dynamic websites that enables a clean separation of concerns and that gives you full control over markup for enjoyable, agile development. ASP.NET MVC includes many features that enable fast.


Models-: Model objects are the parts of the application that implement the logic for the applications data domain. Often, model objects retrieve and store model state in a database. Such as a Product object might retrieve information from a database, operate on it, and then write updated information back to a Products table in SQL Server.


In small applications, the model is often a conceptual separation instead of a physical one. For example, if the application only reads a data set and sends it to the view, the application does not have a physical model layer and associated classes. In that case, the data set takes on the role of a model object.

Views-: Views are the components that display the applications user interface. Typically, this user interface is created from the model data. An example would be an edit view of a Products table that displays text boxes, drop-down lists, and check boxes based on the current state of a Products object.


Controllers-: Controllers are the components that handle user interaction, work with the model, and ultimately select a view to render that displays UI. In an MVC application, the view only displays information; the controller handles and responds to user input and interaction. For example, the controller handles query-string values, and passes these values to the model, which in turn queries the database by using the values.


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/