ASP
ASP
ASP
1
Here the first row is a one-dimensional array of
one column, second row is a one-dimensional
array of two columns and third row is a one-
dimensional array of four columns.
program:-
using System;
class numadd{
public static void Main(){
int[][] x=new int[4][];
x[0]=new int[2]{5,13};
x[1]=new int[3]{7,8,11};
x[2]=new int[4]{2,3,4,5};
x[3]=new int[1]{9};
for(int i=0;i<4;i++){
for(int j=0;j<x[i].Length;j++){
Console.Write(x[i][j]+"\t"); }
Console.Write("\n");}}}
d. Explain method hiding with example.
In a C# program a derived class can have methods with the same signature as that of
its base class methods. This hides the base class methods by its derived class
counterparts and gives a warning. This warning can be suppressed by using the new
keyword with the derive class methods. This means that the members of the base
class are made intentionally hidden by the members having the same signature in the
derived class. The new function will never be invoked by a base class pointer.
Example:-
class demo{
public void disp(){
System.Console.WriteLine("From disp method of base class");
}}
class test:demo{
new public void disp() //This method hides the disp() method of demo class
{
System.Console.WriteLine("From disp method of derived class");
}
public static void Main(){
test t=new test();
t.disp();
}}
Output
From disp method of derived class
Delegate declaration
A delegate is declared with the delegate keyword, followed by return type and the
signature of the method that can be delegated to it. The declaration takes the
following form:
modifier delegate return-type delegate-name (formal-parameters);
where modifier specifies the accessibility of the delegate,
delegate is a keyword,
delegate-name is any valid C# identifier,
formal-parameter defines the parameter list.
Delegate instantiation
Creation of a delegate instance takes the form:
new typename ( invocation-target-expression )
The invocation target instance can refers to either:
a static method
an instance method
Example:-
In the following program delegate instantiation statements are highlighted.
delegate string mydelegate(); //delegate declaration statement
class myclass{
public static string mydelegatemethod1() //delegate method 1
{
System.Console.WriteLine(“from mydelegatemethod1”); //delegate method 2
}
public string mydelegatemethod2()
{
3
System.Console.WriteLine(“from mydelegatemethod1”);
}
}
class Demo
{
public static void Main(){
mydelegate d1 = new mydelegate (myclass.mydelegatemethod1); // static
// method
myclass m=new myclass();
mydelegate d2 = new mydelegate (m.mydelegatemethod2); // instance method
}
}
d. Explain about external style sheet and its advantages. How would you link an HTML
page to an external style sheet?
External style sheets consist of a list of rules that can be applied to one or more web
pages. It helps you to separate the style information from the HTML file. The styles
are external to, or outside of, the web page. It can be linked to any number of web
pages and thereby providing maximum reusability. The external style sheet files
have extension .css.
An external style sheet can be linked to a web page using link tag as follows:
<link rel=“stylesheet” href=“Styles/Sstl.css” type=“text/css” >
AccessKey Enables you to set a key with which a control can be accessed at
the client by pressing the associated letter.
BackColor, Enables you to change background color and text color of a
ForeColor control.
BorderColor This property is used to change the border color of a control.
BorderStyle Using this property border Style can be set to none, dotted,
dashed, solid double, groove etc.
BorderWidth Enables you to change border width of a control.
CssClass Enables you to set the style sheet class for this control.
Enabled Determines whether the control is enabled or not. If the control is
disabled user cannot interact with it.
Font Enables you to change the Font settings.
Height Enables you to set the height of the control.
Width Enables you to set the width of the control.
ToolTip This property enables you to set a tooltip for the control in the
browser and is rendered as a title attribute in the HTML, is shown
when the user hovers the mouse over the control.
Visible Determines whether the control is visible or not.
b. What is the scope of protected data members of a class? Explain method overloading with
example.
Protected Data Members
The protected data members of a class are similar to private data members in many
respects except the fact that they can be accessed also from it’s child classes.
Method Overloading
An operation may have more than one method defined for it. Some of these methods
might represent proposals from various vendors on how an operation should be
specified. Some of these methods could represent staged approaches to implement a
method over a period of time. The choice of a method could be based on what
performs best for a given situation.
The Multiple methods with the same name (for the same operation) are
achieved by varying the number or type of arguments of these methods. This
phenomenon is known as method overloading in C#.
Example:-
using System;
class demo{
public int add(int a,int b){ return a+b; }
public int add(int a,int b,int c){ return a+b+c; }
double add(double a,int b){ return a+b; }
double add(int a,double b){ return a+b; }
4
double add(double a,double b){ return a+b; }
public static void Main(){
demo n=new demo();
Console.WriteLine(n.add(1,2,3)); Console.WriteLine(n.add(2,3));
Console.WriteLine(n.add(4.5,2)); Console.WriteLine(n.add(2,3.2));
Console.WriteLine(n.add(1.2,3.7));
}}
The output of the above program would be:
6
5
6.5
5.2
c. When is CheckedChanged event of a Check Box fired?
Describe the following properties:
i. GroupName property of a Radio Button
ii. Text property of a Label
iii. TextMode property of a Text Box
iv. Checked property of a Radio Button
7
VI. Answer any two of the following: 10
a. What are the benefits using Ajax? Explain about UpdatePanel and ScriptManager.
The major benefit of Ajax is partial page rendering. The partial update of a page does
not necessitate full reload of the page and hence leads to flicker-free page rendering.
UpdatePanel
• It is a container control.
• A page can have multiple update panels.
• The UpdatePanel control enables you to create a flicker free page by providing
partial-page update support to it.
• It identifies a set of server controls to be updated using an asynchronous post back.
• If a control within the UpdatePanel causes a post back to the server, only the
content within that UpdatePanel is refreshed.
ScriptManager
• The ScriptManager control manages client script for AJAX-enabled ASP.NET
Web pages.
• Although this control is not visible at runtime, it is one of the most important
control for an Ajax enabled web page.
• This control work with UpdatePanel control to facilitate partial page rendering in
Ajax enabled web pages.
• There can be only one ScriptManager in an Ajax enabled web page.
b. Write jQuery program that changes the background colour of a paragraph to red and
font colour to yellow when mouse enters over it. Also set the background colour to
white and font colour to black when mouse leaves the paragraph.
c. Explain LINQ to Objects with an example.
• It is used to query collections.
• The LINQ can be used to query any IEnumerable or IEnumerable<T> collection.
• Any enumerable collections such as List<T>, Array, ArrayList, Dictionary<TKey,
TValue> etc. can be queried using LINQ.
Example:-
Label1.Text = "";
string[] hollywood = { "The Darkest Hour", "Heartbreaker",
"Contraband", "Haywire", "The Descendants"};
var query = from x in hollywood
select x;
foreach (string s in query)
{
Label1.Text += s+"<br>";
}
d. Explain the query operators SELECT, FROM, ORDERBY and WHERE in LINQ.
• The select clause is used to retrieve data from the source you are querying.
• It specifies the format of the data returned.
• It can have a set of columns based on the query expression results.
• select adds the result to the return type.
• The from clause defines the collection or data source that the query must act upon.
• var query = from x in nwdb.Customers
select x;
• Where clause is used to filter elements from the data source.
• It selects only those elements for which the ‘where’ clause expression is true.
• Example:-
var query = from x in nwdb.Customers
where x.Country = = "Germany"
8
select x;
• Order by clause is used to arrange the items in the result collection in ascending
or descending order.
var query = from x in nwdb.Products
orderby x.UnitsInStock ascending
select x;
A CSS selector is the part of a CSS rule set that actually selects the content you want
to style. Following are the common type of selectors.
• HTML Tag Selectors
• Class Selector
• ID Selector
• Grouped Selector
• Context Selector
Class Selector
• It styles all elements with the specified class.
• It starts with a period (.) symbol.
Syntax:-
.classname { property:value; }
• Example:-
.test { font-family: ARIAL; font-size: 1em; color: aqua; }
• A class can be applied to selected HTML elements as follows.
h1.test{ color:silver;font-size:2em; }
Here the style ‘test’ is applicable only to h1 tag.
so <p class= "test">STYLE NOT APPLIED</p>
<H1 class="test"> STYLE APPLIED </H1>
Grouped Selector
• If there are multiple elements with the same style then these elements can be
grouped and a common style definition can be made for the group.
• Separate each element in the group with a comma.
• Example:-
9
h1,h2,h3,p{
color:lime;
}
This is equivalent to:
h1{color:lime}
h2{color:lime}
h3{color:lime}
p {color:lime}
c. What is code-behind model in ASP.NET? How is it different from single file model?
The ASP.Net Framework provides a new style of coding to develop web pages. This is called
Code-Behind. In Code Behind Model server maintains two types of files.
• The HTML code page with .aspx extension maintains the code for User Interface
design.
• The .aspx.cs file maintains the program logic.
The file that contains the programming logic (.aspx.cs file) is known as the code behind file.
Only server controls can interact with the code behind the page; not the HTML controls.
Code Behind Vs. Single File
Code Behind Single File
The code is in <script> blocks in the
The HTML and controls are in the .aspx file,
same .aspx file that contains the HTML and
and the code is in a separate . aspx.cs file.
controls.
The code for the page is compiled into a
separate class from which the .aspx file The .aspx file derives from the Page class.
derives.
The program logic is separated from user Both program logic and user interface
interface design code. design code are placed in the same .aspx
So it is easy to understand. file, which makes it cumbersome.
10