Skip to main content

Posts

Showing posts from May, 2014

Featured Post

How to use Tabs in ASP.NET CORE

I want to show Components in a tabs , so first of all create few components. In this project we have three components, First View Component  public class AllViewComponent : ViewComponent     {         private readonly UserManager<ApplicationUser> _userManager;         public AllViewComponent(UserManager<ApplicationUser> userManager)         {             _userManager = userManager;         }         public async Task<IViewComponentResult> InvokeAsync()         {             List<StudentViewModel> allUsers = new List<StudentViewModel>();             var items = await _userManager.Users.ToListAsync();             foreach (var item in items)             {                 allUsers.Add(new StudentViewModel {Id=item.Id, EnrollmentNo = item.EnrollmentNo, FatherName = item.FatherName, Name = item.Name, Age = item.Age, Birthdate = item.Birthdate, Address = item.Address, Gender = item.Gender, Email = item.Email });             }            

How to validate fileupload control in asp.net also choose selected format

In my previous article we already discussed about file upload control . Suppose your picture is required in the form of registration then you must to validate the file upload control. Also you want to take only jpeg, gif and selected format then should use RegularExpressionValidator with regular expression. Now lets take a simple example. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default5.aspx.cs" Inherits="Default5" %> <!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>dotptogramming</title> </head> <body>     <form id="form1" runat="server">     <div>     <asp:FileUpload ID="fileUpload1" runat="server" Width="280px" />

How to pass session value in page title in asp.net

Suppose you have to enter into your account. Now, a session variable created after login and you want to pass this value in page title. If you have a master page then simple use this code in code behind page. Also you can use this code in web form. Lets take a simple example Use only Business Logic code public partial class Default5 : System.Web.UI.Page {     protected void Page_Load(object sender, EventArgs e)     {         Session["username"] = "- ASP.NET CODE";         Page.Title += Session["username"].ToString();     } }   Code Generate the following Output

Dynamically add rows and columns in data table, also bind Gridview with data table

First create instance of DataTable class, which is inside in System.Data namespace. After that you make columns and rows inside the DataTable. First create columns with their data type also insert rows data in it. Source Code <div>         <asp:GridView ID="GridView1" runat="server">         <HeaderStyle BackColor ="Green" ForeColor ="Orange" />         <RowStyle BackColor ="Black" ForeColor ="White" />         </asp:GridView><br />         <asp:Button ID="B1" runat="server" Text="Bind GridView" onclick="B1_Click" />          </div> Business Logic Code using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; public partial class Default4 : System.Web.UI.Page {     protected void Page_Load(object sender, EventArgs e

How to call event in page load method and example of EventHandler class

If you want to add event at run time like click event in page load method. For this types of problem you can use EventHandler class. Create a object of this class also pass new method as a parameter. Source Code <div>              <asp:Button ID="B1" runat="server" CommandName="Add" Text="Button" />          </div>     Business Code     public partial class Default4 : System.Web.UI.Page {     protected void Page_Load(object sender, EventArgs e)     {         B1.Click += new System.EventHandler(this.calculate);     }     protected void calculate(object sender, System.EventArgs e)     {         switch (((Button)sender).CommandName)         {             case "Add": Response.Write("hello");                 break;         }     } } Code Generate the following output

How to Use Filtered TextBox Extender of AJAX in ASP.NET

FilteredTextBoxExtender enables you to apply filtering to a text box control that prevents certain characters from being inserted in the text box. For example, you can limit a text box to either enter only characters, or digit, or dates. This extender is different from ASP.NET validation controls as it prevents the users from entering invalid characters. Lets take an simple example <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %> <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %> <!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></title> </head> <body>     <form id="

Nested Gridview Example in ASP.NET

A gridview with some items and another gridview structure <form id="form1" runat="server">     <div>         <asp:GridView ID="GridView1" runat="server">         <Columns>         <asp:TemplateField>                  <ItemTemplate>             <asp:TextBox ID="TextBox1" runat="server" Text ='<%# Eval("database field") %>' />                  </ItemTemplate>          <ItemTemplate>              <asp:GridView ID="GridView2" runat="server">              <Columns>              <asp:TemplateField>                           <ItemTemplate>             <asp:DropDownList ID="DropDownList1" runat="server">             </asp:DropDownList>                  </ItemTemplate>                            </asp:TemplateField>                            <

Multiple Events call same event Handler in ASP.NET

In ASP.NET,  you can connect multiple Events with same event handler. If you thing about it, this types of code reduce space complexity as well as time complexity. If you use events with separate events handler then take more time. Like <div>     Both Event and methods name are same, both call to same handler.<br /> &nbsp;<asp:Button ID="Button1" runat="server" Text="First Button"              onclick="Button1_Click" /><br />          <asp:Button ID="Button2" runat="server" Text="Second Button" onclick="Button1_Click" /><br />         <asp:Label ID="Label1" runat="server" Text=""></asp:Label>     </div> In my previous article, we have already discussed about it, which is how to determine which web server control is raised. Business Logic Code   protected void Button1_Click(object sender, EventArgs e)    

How to Render HTML Controls in View: Asp.Net MVC

Asp.Net MVC provides a way to write simple programming syntaxes and HTML Helpers convert them in to HTML at runtime to be simply open the pages at client end. These provides generates html and return result as a string. Like other web form controls in Asp.Net, HTML helpers are used to modify HTML, but HTML Helpers does not have an event model/ view state as web form controls have. Programmer can use these helpers by using built in HTML property of the view that are in System.Web.Mvc.Html namespace. We can create our own Html helpers or use built-in provided in the specified namespace. HTML helpers have methods for creating forms, rendering partial views, performing input validation etc. Here are some mostly used html helpers: HTML Links These type of links are used to render an html link on the page, but in MVC they create a link to redirect on a particular action of the controller.         @Html.ActionLink(“Text to Display”, “Action-name”) The first parameter is used to spe

Understanding Attributes in Asp.Net MVC

Earlier article was about to handle browser request from the user and then invokes related controller and actions written for that particular URL. What is to be done after these requests can also be specified by the programmer in Asp.Net MVC, as this article will discuss. Asp.Net MVC provides a way to use some extra features for actions and controller, these features are called Attributes and Filters. We have discusses about Required attribute in creating MVC View Model using required field validations. The first and most attribute, MVC use by default is [Authorize] which specifies which action is to be executed by authenticated users only or it may be used for whole controller. The syntax for this authorize attribute is: [Authorize] Public ActionResult Profile() { return View(); } Now whenever an un-authorized user will try to get access of this profile action, it will redirect the request to login page or the page specified. Attributes can also take parameters specifi

Search Value using Non-Clustered index: SQL Server

Similar to the clustered index , a non-clustered index also contains the index also contains the index key values and the row locators that point to the storage location of the data in a table. However, in a non-clustered index, the physical order of the rows is not the same as the index order. Non-clustered indexes are typically created on columns used in joins and the WHERE clause. These indexes can also be created on columns where the values are modified frequently. The SQL Server creates non-clustered indexes by default when the CREATE INDEX command is given. There can be as many as 249 non-clustered indexes per table. The data in a non-clustered index is present in a random order, but the logical ordering is specified by the index. The data rows may be randomly spread throughout a table. The non-clustered index tree contains the index keys in a sorted order, with the leaf level of the index containing a pointer to the data page and the row number in the data page. The SQL S

Types of Indexes provided by SQL Server

As described in the earlier article indexes can be managed easily. The SQL Server allows you to create the following types of indexes: Clustered index Noclustered index Clustered Index A clustered index is an index that sorts and stores the data rows in the table based on their key values. Therefore, the data is physically sorted in the table when a clustered index is defined on it. Only one clustered index can be created per table. Therefore, you should build the index on attributes that have a high percentage of unique values and are not modified often. In a clustered index, data is stored at the leaf level of the B-Tree. The SQL Server performs the following steps when it uses a clustered index to search for a value: The SQL Server obtains the address of the root page from the sysindexes table, which is a system table containing the details of all the indexes in the database. The search value is compared with the key values on the root page. The page with the highest

How to Create and Manage Indexes in SQL Server

Database developer is often required to improve the performance of queries. SQL Server allows implementing indexes to reduce the execution time of queries. In addition they can restrict the view of data to different users by implementing views. The SQL Server also provides an in-built full-text search capability that allows fast searching of data. This article discusses how to create and manage indexes and views. Creating and Managing Indexes When a user queries data from a table based on conditions, the server scans all the data stored in the database table. With an increasing volume of data, the execution time for queries also increases. As a database developer, you need to ensure that the users are able to access data in the least possible time. SQL Server allows you to create indexes on tables to enable quick access to data. In addition, SQL Server allows you to create XML indexes for columns that store XML data. At times, the table that you need to search contains volumino

Complaints Management Project in ASP.NET

Download this project Project cost : 200Rs or $8 Pay me at: PayPal id : saini1987tarun@gmail.com Via bank transfer ICICI bank account number is :    153801503056 Account holder name is :                 Tarun kumar saini IFSC code is :                                   ICIC0001538 SBBJ bank detail :                             61134658849 Account holder name :                        Tarun kumar saini IFSC code :                                        SBBJ0010398 CONTACT ME narenkumar851@gmail.com Introduction In this project, you can create your complaints to admin department. Review your complaints by the admin department and try to solve the problem. Project Module I have two module in this project first one is consumer module and last one admin module. How to work(Step by step guide) Step-1 : First to complete the consumer registration. Step-2 :  Login in your account using consumer login panel. Step-3 : Fill the complaints form, after login. Step-4 : Chec

How to Modify XML Data using Functions in SQL Server

Similar to any other type of data, programmer might also need to modify the XML data. To modify data, you can use the modify function provided by the XML data type of the SQL Server. The modify function specifies an XQuery expression and a statement that specifies the kind of modification that needs to be done. This function allows you to perform the following modifications: Insert: Used to add nodes to XML in an XML column or variable. For example, the management of AdventureWorks wants to add another column specifying the type of customer, in the CustDetails table. The default value in the Type column should be ‘Credit’. To resolve this problem, the database developer of AdventureWorks will create the following query: UPDATE CusomtDetails SET Cust_Details.modify (‘ inser attribute Type{“Credit”} as first into (/Customer) [1]’) Replace: Used to update the XML data. For example, James Stephen, one of the customers of AdventureWorks, has decided to change his customer type from C

Add 3 months in current month in asp.net

 <form id="form1" runat="server">     <div>             <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Click" BackColor="#99CCFF" />         </div>     <asp:Label ID="Label1" runat="server" BackColor="Yellow"></asp:Label>     </form> Code Behind  protected void Button1_Click(object sender, EventArgs e)     {         {                     DateTime now = DateTime.Now;                     DateTime after3Months = now.AddMonths(3);             Label1.Text = "now = " + now.ToLongDateString();             Label1.Text += "<br /><br />after added 3 months to now= ";             Label1.Text += after3Months.ToLongDateString();         }     } Code Generate the following output

Example of Append string using StringBuilder class in asp.net

 <form id="form1" runat="server">     <asp:Button ID="Button1"      runat="server"      onclick="Button1_Click"      Text="Click"         Width="74px" BackColor="#FF6666" />     <div style="width: 93px">             <asp:Label ID="Label1"          runat="server"          Text="Label" BackColor="Yellow" ForeColor="Black"></asp:Label>         </div>     </form>  Code Behind  protected void Button1_Click(object sender, System.EventArgs e)          {         StringBuilder stringA = new StringBuilder();         stringA.Append("those are text. ");         StringBuilder stringA2 = new StringBuilder(" another text.");         stringA.Append(stringA2);         Label1.Text = stringA.ToString();      } Code Generate the following output

How to Retrieve XML Data Using XQuery

In addition to FOR XML, SQL Server allows programmer to extract data stored in variables or columns with the XML data type by using XQuery. XQuery is a language that uses a set of statements and functions provided by the XML data type to extract data. As compared to the FOR XML clause of the SELECT statement, the XQuery statements allow you to extract specific parts of the XML data. Each XQuery statement consists of two parts, prolog and body. In the prolog section, you declare the namespaces. In addition, schemas can be imported in the prolog. The body parts specifies the XML nodes to be retrieved. The XQuery language includes the following statements: For: Used to iterate through a set of nodes at the same level as in an XML document. Let: Used to declare variables and assign values. Order by: Used to specify a sequence. Where: Used to specify criteria for the data to be extracted. Return: Used to specify the XML returned from a statement. The XQuery statements also us

How to Define Methods with Behavior: Java

Objects have behavior that is implemented by its methods. Other objects can ask an object to do something by invoking its methods. This section tells you everything you need to know about writing methods for your Java classes. In Java, you define a class’s methods in the body of the class for which the method implements some behavior. Typically, you declare a class’s methods after its variables in the class body although this is not required. Implementing Methods Similar to a class implementation, a method implementation consists of two parts: the method declaration and the method body methodDeclaration {         methodBody } The Method Declaration At minimum, a method declaration has a name and a return type indicating the data type of the value returned by the method: returnType methodName( ) { . . . } This method declaration is very basic. Methods have many other attributes such as arguments, access control, and so on. Objects as Instances of Class A class def

How to Declare Member Variables in Classes: JAVA

A class’s state is represented by its member variables. You declare a class’s member variables in the body of the class. Typically, programmer declare a class’s variables before you declare its methods, although this is not required. classDeclaration {         member variable declarations         method declarations } To declare variables that are members of a class, the declarations must be within the class body, but not within the body of a method. Variables declared within the body of a method are local to that method i.e., available and accessible only inside the method. Types Class variable (static variable):  A data member that is declared once for a class. All objects of the class type, share these data members, as there is single copy of them available in memory. The class variables are declared by adding keyword static in front of a variable declaration. Instance variable: A data member that is created for every object of the class. For example, if there are 10

Fix A table control was not found in the template for data list

<!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></title>     <style type="text/css">         #form1         {             width: 162px;             height: 384px;         }     </style> </head> <body>     <form id="form1" runat="server">    <asp:DataList ID="DataList1" runat="server" DataKeyField="Sno"          DataSourceID="SqlDataSource1" CellPadding="0" ExtractTemplateRows="True">         <ItemTemplate>             Sno:             <asp:Label ID="SnoLabel" runat="server" Text='<%# Eval("Sno") %>' />             <br />             name