Skip to main content

Posts

Showing posts from 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 });             }            

Get Content and Attributes in jQuery

Getting and assigning content of elements in jQuery is very simple because of its in-built functions . JQuery provides many in-built functions that can be used to get content of any element and can set html part for any element. JQuery library contains many DOM related functions that make it easy to use and understand how it is working. Programmer can easily manipulate content of any element or attributes by using existing functions . In rare chances programmer have to write its own functions with collection of JQuery library functions. To get content of any element on the web-page, programmer can use following three mostly used functions: val(): get or set the value of forms field. text(): get or set the text content of selected elements. html(): get of set the whole content of selected elements including html markup. Lookout the following example through which we will use all three types of functions and show the values returns by them. $("#btn").click(funct

Callback Functions Execution in jQuery

Callback functions are function which can be invoked under certain conditions. These functions executes after current effect have been finished. As the effect completed, the function reference specified as callback will be executed. JQuery statements are executed line after line in a sequence and perform action written. In case of effects discussed earlier, next line (whatever you write) will be execute before the effect completes its part. If the next line depends on the effect then it can create errors. Callback function reference will execute after the current effect finished completely. These functions can easily remove those errors, here is the syntax: $(selector).show(speed, callback); Following example will show an alert after div is shown on the button click: $("#btnShow").click(function(){ $("#divToShow").show("slow", function(){         alert("Div has been shown");         }); }); In the above code a callback function

SiteMapPath not visible in visual studio 2013

When i run the SiteMapPath in visual studio 2010 then i found that it run successfully. When i run same sitemap file in visual studio 2013 then didn't run. I found the Error, that error is: .aspx extension Because visual studio 2013 support hide extension functionally or you can say it provide friendly url to the users. Like http://localhost:25367/marketus Here, marketus is the page name, not a directory. So problem structure is: Now the solution is, remove .aspx extension of the url attribute from the web.sitemap file. Now you can see after removing the extension.  Now the output page of the file is:

Create an Object using New Operator: Java

New operator is used to create a new object of an existing class and associate the object with a variable that names it. Basically new operator instantiates a class by allocating memory for a new object and returning reference to that memory. Every class needs an object to use its member and methods by other classes. Programmer have to create that object using new operator to use functionality provided by that class. Following is the syntax to create new object of an existing class: Class_variable =new Class_Name(); This syntax basically describes some points about new operator as below: Allocates memory to class_variable for new object of class. It invokes object constructor. Requires only single postfix argument which calls to constructor. Returns reference to memory which is usually assigned to variable of appropriate type. Following statement will create an object of city class and allocate memory to this newly created object: City metro;

TextMode property of TextBox in ASP.NET

In visual studio 2010 you can assign only three values to the TextMode property , Those values are SingleLine , MultiLine and Password. But in visual studio 2012 you can set lots of value to the TextMode property Those values are SingleLine , MultiLine, Password, Email,Date , DateTime,URl etc All values are given below diagram. Now all values we are using one by one : MultiLine : In MultiLine TextBox you can take multiple rows but in single line TextBox you can take only single row. MultiLine TextBox is used where you need multiple rows like address of person.  Lets take an example of MultiLine TextBox . Drag one TextBox control to the design window and set MultiLine to TextMode property. <%@ Page Language="C#" %> <!DOCTYPE html> <script runat="server"> </script> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server">     <title></title> </head> <body

SiteMap Path example in ASP.NET

Using the SiteMap Path class you can navigate a website. It displays a set of Text or images Hyperlinks. Inheritance hierarchy of SiteMapPath class are: System.Object     System.Web.UI.Control       System.Web.UI.WebControls.WebControl          System.Web.UI.WebControls.CompositeControl             System.Web.UI.WebControls.SiteMapPath Lets take an simple example of SiteMap Path  To create Web.Sitemap, right click the website name. A context menu appears. Select the Add New Item option from the context menu. The Add New Item dialog box appear. Select Site Map from the option available. This will create a new web.sitemap file in the website.  The Web.sitemap file consists of navigational details for an application. You can set the title, URL, and other information for each page by using the Web.sitemap file. code, copy and paste into your sitemap file. Article : How to use Menu Control in ASP.NET Video : A simple video contain how to use menu and sitemap file   <

Program to find sum of even and odd numbers (using one for loop) in C

Instead of using two for loops as in the previous program, only one for loop can be used. Let us see how this can be achieved. sum= 0; /* To add all numbers */ for(i=1; i<=n; i++) { sum = sum+i; } It is easy to say that we are computing the sum of all the numbers from 1 to n. To add only even numbers or to add numbers, the code can be changed as shown below: esum=0;                          /* To store sum of even numbers */ osum = 0;                        /* To store sum of odd numbers */ /* To generate the integer from 1 to n */ for(i=1; i<=n; i++) { if(i % 2 == 0)                     /* If even */ esum = esum + i;               /* Add to even sum */ else osum = osum + i; } Thus, after the control comes out of the for-loop, the variable esum contains the sum of even numbers and the variable osum contains the sum of odd numbers. The result can be printed using the following statements: printf("Sum of even numbers = %d\n",esum); printf(&quo

How to insert data into multiple table in ASP.NET

I have two table, such as complaint table and status table. Now, i want to add data in both table through same SqlCommand class instance. Now, first to prepare the Connection using SqlConnection class, after that design the query for first table after inserting the data, we can add data into other table. You can check the complete. Source Code <table style="width:100%;">     <tr>         <td class="style3">             Complaint against To</td>     </tr>     <tr>         <td class="style1">             Name :&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&

How to run Applet in Netbean IDE

We are very familiar with java programming, when we come to applet programming then we need some resources like browsers, AppletViewer etc to run the applet code. When i run the applet code in command prompt using following command: appletviewer filename.html  Applet viewer was not appear in windows 8.1. Then lastly i was decide that i shall install Netbean IDE for applet code. import java.awt.*;  import java.applet.*; public class design extends Applet  {  public void paint(Graphics g) { g.drawString("Hello World",50,100); } } Now, copy this code and following some instructions which is given in the youtube video

Prevention from SQL Injection attack in ASP.NET

In myPrevious article, we have already learn about SQL injection attack . We saw that if we use Text Box for retrieving data from the database then other queries also perform with the same database. So, Microsoft provide, Parameterized query for DML and DQL statements. Like Replace this statement with the parameterized query Direct Interface with TextBox (SQL Injection Attack Possible) cmd.CommandText = "Select * from [TableName] where name='"+TextBox1.Text+"'"; Resolve this problem by the parameterized query cmd.CommandText = "Select * from [TableName] where name=@name1"; cmd.Parameter.AddWithValue("@name1",TextBox1.Text); Now that video give more clearance :   

Program to add the numbers which are divisible by 5 in C

Let us write a program to print all the numbers between N1 and N2 which are divisible by 5. Then, compute the sum of those numbers. The numbers between N1 and N2 can be added using the following statement: sum =0; for(i=n1; i<=n2; i++)       /* i start from n1 and goes up to n2 */ { sum =sum+i;                    /* Can be written as sum +=i */ } But, it is required to add those which are divisible by 5 only. This can be achieved by taking only those values of i which are divisible by 5 and the program can be modified as follows: sum =0; for(i=n1; i<=n2; i++) { if(i%5 == 0) { sum +=i; } } The complete algorithm are shown below: Algorithm : DIVBY5. [This algorithm prints the numbers divisible by 5 between n1 and n2] Step 1 : [Enter lower & upper limits] Read : n1, n2 Step 2 : [Initialize] sum =0 Step 3 : [Generate and add the number if divisible by 5] for i=n1 to n2 in step 1 if(i%5 ==0) sum = sum+i [End of if] [End of for] Step 4 : [Outpu

Program to find sum of squares of first N natural numbers in C

Let us design the algorithm and write the program to find the sum of the following series: 1 2 +2 2 +3 2 +4 2 +....................................................N 2 We know the program segment to add all the numbers from 1 to N. The program segment is: sum=0; for(i=1; i<=n; i++) { sum = sum+i; } But, to add 1 2 ,  2 2 ,  3 2 ,  4 2 ,  ...............N 2     it is necessary to replace the statement: sum = sum+i; by the statement: sum = sum+i*i; The algorithm and flowchart to find the sum of squares of all natural numbers are as follows: Algorithm : SERIESSUM Step 1: [Input the number of terms] Read: n Step 2: [Initialization] sum =0 Step 3: [Find the sum of all terms] for i=1 to n in steps of 1 do sum = sum + i*i [End of for i] Step 4: [Output the sum] Write : sum Step 5: [Finished] Exit. The complete program to find the sum of the given series is shown below: Example : Program to add the series  1 2 +2 2 +3 2 +4 2 +.......................

Program to simulate calculator using switch in C

The input is the expression of the form (a op b) where a and b are the operands and op is an operator. For example 10+20. Based on the operator, the operation is performed and the result is displayed. The complete algorithm along with the flowchart is shown below: Algorithm: CALCULATOR Step 1: [Read expression of from (a+b)] Read: a, op, b Step 2: [perform the required operation] switch(op) case "+" : res = a+b case "-" : res = a-b case "*" : res= a*b case "/" : if (b==0) Write : "Divide by 0" Exit else res = a/b [End of if] default : Write: ' Invalid operator' Exit [End of switch] Step 3: [Output the result] Write: res Step 4: [Finished] Exit. The equivalent C program to perform various operations such as addition, subtraction, multiplication and division is shown below: Program #include<stdio.h> #include<process.h> main( ) { int a, b, res; char op; /* can be +, - , *,, or / *

Program to find numbers within range n1 and n2 in C

Just now, we have seen, how to check whether a given number m is prime or not. Let us modify this program to generate prime numbers within the range n1 and n2. Procedure : Assume m varies from n1 to n2. If m is prime let us display it. Otherwise, take the next number in the range and check for prime number. If it is prime, display it; otherwise, take the next number and repeat the procedure. Thus, all prime numbers are displayed in the range n1 to n2. So, when m is prime, in place of displaying the message " The number is prime", let us print the prime number. If m is not prime, instead of displaying the message "The number is not prime", take the next number in the range. If these modifications are done to the program discussed in the previous section, then prime numbers within the range are generated. The modified program is shown below: #include<stdio.h> void main( ) { int n, n1, n2, i, count, prime; printf("Enter n1 and n2:\n"); scanf(

Program to check whether a number is prime or not in C

Before we check whether a number is prime or not, we should know the answer for the question "What is a prime number ?" Definition : A number which is only divisible by 1 and itself is a prime number. For example, numbers such as 1, 2, 3, 5, 7, 11 etc. are not divisible by any numbers other than 1 and themselves. So, they are all prime numbers. But, the numbers such as 4, 6, 8, 16 etc., are divisible by 2 and hence they are non-prime numbers. The number 9 is divisible by 3 and hence it is also no-prime number. Now, let us see " How to check whether a given number is prime or not?" Procedure : Consider the number 16. It is not divisible by 9, 10, 11, 12, 13, 14 and 15 which are all greater than 16/2. So, the first point to remember is: A number m cannot be divisible by a number which is greater than m / 2. In our case m is 16. It is divisible by the numbers 2, 4 and 8 which are less than or equal to 16/2. The second point to remember is: A numbe

Adding Animation to Web Page Part-2: jQuery Effects

JQuery library have all the effects for adding animation as discussed in earlier article . How to show or hide an element, sliding effects on an element or perform any custom animation on web-page have been discussed in my previous discussion. Wherever these function didn’t work on the page then there may be some script error or you are defining the function with wrong syntax. Whatever the error be, jQuery library is there for help any type of definition, syntaxes or any example. User can apply fading on an element, and make that element out of visibility, by using below functions specially created for this functionality. Reading an element’s description and do some practical with them are two different tasks. So just read and perform practical to clarify all these effects . fadeIn(): used to fade in a hidden element on the web-page. fadeOut(): used to fade out a hidden element on the web-page. fadeTo(): allows fading to a given opacity. fadeToggle(): used to toggle betw

Adding Animation to Web Page: jQuery Effects

JQuery library have all the effects for adding animation user can imagine/think about like to animate, fade, toggle, show, hide and etc. All these animation have their own functions according to their job. jQuery  methods allow users to easily use these effects with minimum configuration. In other context we can show or hide any element on the page by using these effects to make better UI. These animation can be done in any event of an existing element. I have listed some of these methods including a brief description: hide() : will hide the related element. show() : will show related element. toggle() : show of hide related element. (If element is shown then it will hide) slideDown()/slideUp() : show or hide related element with sliding motion. slideToggle() : show of hide related element with sliding motion. animate() : this method is used for custom animation. These methods have also some parameter to be used with e.g. speed (represents predefined speed among slow, n

Program to check for leap year in C

Before writing the program let us see "What is a leap year?" Definition: A year which satisfies one of the following two cases: It is divisible by 4 and should not be divisibly by 100  Divisible by 400 If one of the condition is true, it is a leap year. But, if both condition are false, the year is not a leap year. The following table shows whether a year is a leap year or not along with the reasons: The partial code for this can be written as follows: if(year % 4 == 0 && year % 100 !=0) || (year % 400 == 0) printf ("%d is a leap year \n",year); else printf("%d is not a leap year \n"); The complete program is shown below: Program #include<stdio.h> void main( ) { int year; printf("Enter the year"); scanf("%d",&year); if((year %4==0 && year %100!=0 ) !! (year %400 == 0)) printf("%d is a leap year ",year); else printf("%d is not a leap year",year); }

HTML applet tag and their attributes

Applet is a tag in html that is used to create an applet window or applet in an html document.   Example <!DOCTYPE html> <html> <head> <title>HTML applet Tags and their attributes</title> </head> <body> <applet code="classname.class" width="300" height="200"> </applet> </body> </html>   Applet tag has following attributes   Code : This attribute takes the class name of the applet code that is to be displayed . Class is the compiled code for applet   e.g.   <applet code="abc.class" width="200" height="200" />   Height : This attribute takes values in pixels to define the height of the applet.   Width : This attribute takes values in pixels to define the width of the applet.   Vspace : This attribute takes values in pixels to specify how much space is to be left above and below the object.   Hspace : This attribute takes values

How to retrieve images from database table in ASP.NET

Database is a storage system, through which we can store data permanently into the secondary storage device. Similar to programming languages, database also take some data types for categorize data. like int, Text, DateTime etc. Now, we will discussed on image. In this example we will retrieve images from database. First we store images into database, actually images is not stored directly, so for that path of the images is stored into the database. Now, bind the GridView with the image field.   <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server">     <title></title> </head> <body>     <form id="form1" runat="server">     <div>       </div>         <asp:GridView ID="GridView1" runat=&quo

Program to find the larger of two numbers using ternary operator

larger = (a>b)? a:b; The simple logic behind the program is, when a(variable) is greater than b, the value of a is assigned to larger(variable). Otherwise, the value of b is assigned to larger. The program to find the larger of two numbers using ternary operator is shown below: #include<conio.h> #include<stdio.h> void main() { int a,b,larger; clrscr(); printf("Enter a and b:\n"); scanf("%d%d",&a,&b); /*The larger of a and b is stored in larger*/ larger=(a>b)?a:b; printf("Larger=%d\n",larger); getch(); } Code generate the Following output

Debugging C program

Debugging is the process of isolating and correcting the errors. One simple method of debugging is to place printf( ) statements throughout the program to display the values of variables. It displays the dynamics of a C program and allows the programmer to examine and compare the data at various points. Once the location of an error is identified and corrected, the debugging statements should be removed. We can use the conditional compilation statements to switch on or off the debugging statements. Another approach is to use the process of deduction. Here, we arrive at the errors, using the process of elimination and refinement. This is done using a list of possible causes of the error. The third error-locating method is to backtrack the incorrect results through the logic of the program until the mistake are located. The program is traced backward until the error is located.

How to create aspx page at run time in ASP.NET

ASPX stands for active server page extension. We know that visual studio create a aspx page for dynamic application. Also one another page is created for business logics. If you want to create both pages(presentation+business logic) through code file then first to create two array for both pages. After that save the file through file handling in same solution. Source Code <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server">     <title></title>   </head> <body>     <form id="form1" runat="server">       Enter page Name  <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />         <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Cli