Showing posts with label Asp.Net. Show all posts
Showing posts with label Asp.Net. Show all posts

Sunday, December 15, 2013

Jquery datepicker prevent from selecting future date in Asp.Net

Hello Friends,

Today I am writing this post for developer who face problem to disable future date using Jquery datepicker in asp.net.



First of all you have to use "jquery-1.7.1.min.js","Jquery-ui.min.js" and "jquery-ui.css that can be dowload it form 
http://jqueryui.com/download/all/ and add in your page. 

For add datepicker add below code inside tag.

        $(document).ready(function () {             var d = new Date();
            var curr_year = d.getFullYear();
            $("#<%= txtBirthDate.ClientID  %>").datepicker(
        {
           yearRange: '1900:' + curr_year,
          changeMonth: true,
          changeYear: true,
          maxDate: '-1d',
          buttonImage: '../Theme/image/icon_calendar.png',
          buttonImageOnly: true,
          showOn: 'button',
          dateFormat: 'DD, MM d, yy'
        });
});






and Add a Textbox with Id="txtBirthDate" in your Asp.net Page.

Enjoy coding.....

If you like this post share it.. If you encounter any problems, feel free and 
comment below to find solution. Share Your Experience with us.


Monday, August 26, 2013

Create Connection String in Asp.net using web.config file

Hello Friends,

Today I am writing this post because of I found out that beginners got a problem to create connection with database in web config file in asp.net. So, Solution is here. Enjoy it.....

Web Config File

<configuration>

  <connectionStrings>

    <add name="nameofConnection" connectionString="Data Source=servername; Initial Catalog=DatabaseName; User ID=UserName; Password=Password;"/>

  </connectionStrings>

  <system.web>
    <compilation debug="false" targetFramework="4.0" />
  </system.web>

</configuration>


Default.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">
    <title>Connection String Demo</title>
</head>

<body>
    <form id="form1" runat="server">
    <div>
        <asp:GridView runat="server" ID="GridView1">
        </asp:GridView>
    </div>
    </form>
</body>
</html>



Default.aspx.cs

Add System.Configuration and System.Data.SqlClient namespace to add connection with sql.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page
{
   protected void Page_Load(object sender, EventArgs e)

   {

string connectionString = ConfigurationManager.ConnectionStrings["nameofConnection"].ConnectionString;

string query = "SELECT ProductID, ProductName, UnitPrice FROM tblProduct";
       
SqlDataAdapter da = new SqlDataAdapter(query, connectionString);

DataTable table = new DataTable();

da.Fill(table);

GridView1.DataSource = table;

GridView1.DataBind();

   }
}

If you like this post share it.. If you encounter any problems, feel free and comment below to find solution. Share Your Experience with us.










Sunday, August 25, 2013

Creating a virtual directory in IIS 7.5 and 7.0

Hello Friends,

Many times we face the problem to host our website on local
machine to createa virtual directory, So solutions is here for creating virtual directory in IIS 7.5 and 7.0.

Since IIS 7, there exists a separate concept for a virtual directory and an application.
You can map a virtual directory to a physical directory that is located on a local  a or remote computer. The physical directory (under the specified name of the virtual directory) then becomes part of the application's URL.
An application, on the other hand, is a group of files that provides services over protocols. So if you want to run your website as http://localhost/Demo, you have to use an application instead of a virtual directory and specify Demo as the application's alias.

To create a virtual directory:
Open IIS Manager
On Windows 7: Open Start -> Control Panel -> System and Security category ->
                        Administrative Tools -> Internet Information Services (IIS) Manager.


         On Windows Server 2008 or Windows Vista: Open 
Start -> Control Panel ->
              System and Maintenance category -> Administrative Tools ->
                                      Internet Information Services (IIS) Manager.
Expand local computer -> Sites -> right-click on Default Web Site (or other website if you're running multiple websites on the same computer) and choose Add Virtual Directory... 

An Add Virtual Directory dialog appears.
Enter the Virtual Directory Alias. If you want the website to run as http://localhost/KenticoCMSDemo, enter alias KenticoCMSDemo.
Type a path or browse to the physical directory that contains the chosen directory.


5. Click 
OK.
The system creates a new virtual directory.
Right-click the virtual directory and choose Convert to Application.
An Add Application dialog appears.
7.Click Select... and choose the ASP.NET v4.0 application pool from the drop-down menu.

8. Click OK.
The system converts the virtual directory to an application.
Alternatively, you can create an application in one step by right-clicking a web site and choosing Add Application... and filling the required information in the Add Application dialog as mentioned above.
Configuring application pools in IIS 7 and IIS 7.5
Application Pools provide you with additional level of website management. They are supported only by Windows Server 2003/2008/Vista/7. You can configure them in the Internet Information Services (IIS) Manager under local computer -> Application Pools.


  
You can check and change the assigned application pool by right-clicking an application under local computer -> Sites -> Default Web Site (or other web site) and selecting Manage Application -> Advanced Settings...

  
You can set the Recycling and other options by right-clicking on an application pool under local computer -> Application Pools and selecting Advanced Settings....

  

If you like this post share it.. If you encounter any problems, feel free and comment
 below to find solution. Share Your Experience with us.



Wednesday, August 21, 2013

12 Steps To Create C# Documentation Using Xml Using SandCastle

C# Documentation Using Xml

Hello Friends,

Today I am writing this post because of creating a documentation of coding for .Net developers.  Documentation will to understand code standard, programming tricks and project that is created by other.


C# Documentation Using Xml

1.    First of all Programmer/Developer have to write xml comment 
       code  in Source  file.

Example:
/// <summary>
/// The constructor sets the name, age and cash
/// </summary>
/// <param name="name">The name of the guy</param>
/// <param name="age">The guy's age</param>
/// <param name="cash">The amount of cash the guy starts with</param>

 2.   There are some predefined tags for xml comment.
        Summary, Param, returns, remarks, code, example etc.

3.    After creating comment create exe/dll and xml file of project which
       will be reside   inside bin or bin\debug folder of project. For 
       creating  xml

4.    Open Solution Explorer--> Right Click on project and open 
       properties-->choose Build tag and Inside Build tag check on
       checkbox XML documentation File and give the appropriate 
       name.



5.     After that build the project for creating the xml and dll/exe.
        For creaing documentation use Microsoft sandcastle tool.

6.     SandCastle Documentation Compiler Tools, can be downloaded 
        at  http://sandcastle.codeplex.com/releases/view/47665

        SandCastle Help File Builder, a tool with GUI to generate 
       documentation  file, can be downloaded at
          http://shfb.codeplex.com/

7.     After Installing SandCastle open SandCastle Help File Builder GUI
        From program menu. Screen would be like

8.    Create New Project from File Menu and give the name of project
       And save it anywhere besides (Desktop, My Document).

9.   HTML HELP 1 (CHM)  is used for creating chm help file.
      WEBSITE (HTML/ASP.NET) is used for creating web page.



          Framework according to your project like 3.5, 4.0 etc.

10.    Right click on Document Source menu from project explorer and
         Choose Add Document Source and select your dll/exe and xml file
         from project.

11.   From path tab give the Help Content Output Path  it could be
        Anywhere besides (Desktop, My Document) and Folder 
        name should be  “Help”


12.   And Last click on Build Project from Documentation Menu. And
         it will create all the file in given path folder.

If you like this post share it.. If you encounter any problems, feel free and comment
 below to find solution. Share Your Experience with us.



Tuesday, August 20, 2013

ASP.NET Application and Page life cycle

Hi Friends, 

Welcome in DotNet Developers Cafe. This is my first post. So, read it and enjoy...



The ASP.Net life cycle could be divided into two groups:
  1. Application Life Cycle
  2. Page Life Cycle
ASP.Net Application Life Cycle:
The application life cycle has the following stages:
  • User makes a request for accessing application resource, a page. Browser sends this request to the web server.
  • A unified pipeline receives the first request and the following events take place:
    • An object of the ApplicationManager class is created.
    • An object of the HostingEnvironment class is created to provide information regarding the resources.
    • Top level items in the application are compiled.
  • Response objects are created . the application objects: HttpContext, HttpRequest and HttpResponse are created and initialized.
  • An instance of the HttpApplication object is created and assigned to the request. The request is processed by the HttpApplication class. Different events are raised by this class for processing the request.
ASP.Net Page Life Cycle:
When a page is requested, it is loaded into the server memory, processed and sent to the browser. Then it is unloaded from the memory. At each of this steps, methods and events are available, which could be overridden according to the need of the application. In other words, you can write your own code to override the default code.
The Page class creates a hierarchical tree of all the controls on the page. All the components on the page, except the directives are part of this control tree. You can see the control tree by adding trace= "true" to the Page directive. We will cover page directives and tracing under 'directives' and 'error handling'.
The page life cycle phases are:
  • Initialization
  • Instantiation of the controls on the page
  • Restoration and maintenance of the state
  • Execution of the event handler codes
  • Page rendering
Understanding the page cycle helps in writing codes for making some specific thing happen at any stage of the page life cycle. It also helps in writing custom controls and initializing them at right time, populate their properties with view-state data and run control behavior code.
Following are the different stages of an ASP.Net page:
  • Page request . when ASP.Net gets a page request, it decides whether to parse and compile the page or there would be a cached version of the page; accordingly the response is sent

  • Starting of page life cycle . at this stage, the Request and Response objects are set. If the request is an old request or post back, the IsPostBack property of the page is set to true. The UICulture property of the page is also set.

  • Page initialization . at this stage, the controls on the page are assigned unique ID by setting the UniqueID property and themes are applied. For a new request postback data is loaded and the control properties are restored to the view-state values.

  • Page load . at this stage, control properties are set using the view state and control state values.

  • Validation . Validate method of the validation control is called and if it runs successfully, the IsValid property of the page is set to true.

  • Postback event handling . if the request is a postback (old request), the related event handler is called.

  • Page rendering . at this stage, view state for the page and all controls are saved. The page calls the Render method for each control and the output of rendering is written to the OutputStream class of the Page's Response property.

  • Unload . the rendered page is sent to the client and page properties, such as Response and Request are unloaded and all cleanup done.
ASP.Net Page Life Cycle Events:
At each stage of the page life cycle, the page raises some events, which could be coded. An event handler is basically a function or subroutine, bound to the event, using declarative attributes like Onclick or handle.
Following are the page life cycle events:
  • PreInit . PreInit is the first event in page life cycle. It checks the IsPostBack property and determines whether the page is a postback. It sets the themes and master pages, creates dynamic controls and gets and sets profile property values. This event can be handled by overloading the OnPreInit method or creating a Page_PreInit handler.
  • Init . Init event initializes the control property and the control tree is built. This event can be handled by overloading the OnInit method or creating a Page_Init handler.
  • InitComplete . InitComplete event allows tracking of view state. All the controls turn on view-state tracking.
  • LoadViewState . LoadViewState event allows loading view state information into the controls.
  • LoadPostData . during this phase, the contents of all the input fields defined with the <form> tag are processed.
  • PreLoad . PreLoad occurs before the post back data is loaded in the controls. This event can be handled by overloading the OnPreLoad method or creating a Page_PreLoad handler.
  • Load . the Load event is raised for the page first and then recursively for all child controls. The controls in the control tree are created. This event can be handled by overloading the OnLoad method or creating a Page_Load handler.
  • LoadComplete . the loading process is completed, control event handlers are run and page validation takes place. This event can be handled by overloading the OnLoadComplete method or creating a Page_LoadComplete handler.
  • PreRender . the PreRender event occurs just before the output is rendered. By handling this event, pages and controls can perform any updates before the output is rendered.
  • PreRenderComplete . as the PreRender event is recursively fired for all child controls, this event ensures the completion of the pre-rendering phase.
  • SaveStateComplete . state of control on the page is saved. Personalization, control state and view state information is saved. The HTML markup is generated. This stage can be handled by overriding the Render method or creating a Page_Render handler.
  • UnLoad . the UnLoad phase is the last phase of the page life cycle. It raises the UnLoad event for all controls recursively and lastly for the page itself. Final cleanup is done and all resources and references, such as database connections, are freed. This event can be handled by modifying the OnUnLoad method or creating a Page_UnLoad handler.

If you like this post share it.. If you encounter any problems, feel free and comment below to find solution. Share Your Experience with us.