What is the use of params keyword? Give an example.

Tuesday, July 14, 2009


params is used on such situations where the number of arguments to a method is not known until runtime. If you prefix the params keyword followed by the type as array without size, then you can pass as many arguments as you want.


Ex:
using System;
using System.Collections.Generic;
using System.Text;

namespace ParamSample
{
class Program
{
public static void PrintWords(params String[] p)
{
for (int i = 0; i < p.GetLength(0); i++)
{
System.Console.WriteLine(p[i]);
System.Console.Read();
}
}

static void Main(string[] args)
{
PrintWords("1","2","3");
}
}
}



www.codecollege.NET

What is the use of the AssociatedControlID?


If you want to associate a control with Label, then you can give an access key to the label control and set the AssociatedControlID property of the Label to the control to which you want the label to associate. When you do so, upon clicking the AccessKey Focus will be set to the Associated Control.


Ex:
<form id="form1" runat="server">
<div>
<asp:Label ID="lblName" runat="server" AccessKey="N" AssociatedControlID="TextBox1"
Text="Name"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />
<br />
<asp:Button ID="Button1" runat="server" Text="Button" AccessKey="B" OnClick="Button1_Click" /></div>
</form>



www.codecollege.NET

Daily Tips- Tip #8 - How will set an Accesskey for a button?


You can do that by setting the AccessKey attribute of the button.


Ex:
<asp:Button ID="btnTest" runat="server" AccessKey="T" Text="Test" OnClick="btnTest_Click" />



www.codecollege.NET

Daily Tips- Tip #7 - How will you make a button the default button?


You can do that by setting the DefaultButton attribute of the form in which the button is present.


Ex:
<form id=f1 defaultbutton="btnSubmit" runat="server">
<asp:textbox id="textbox1" runat="server"/>
<asp:button id="button1" text="btnSubmit" runat="server"/>
</form>



www.codecollege.NET

What is the purpose of AutoEventWireup Page directive?


When set to true , it ensures that the event handlers for the page will be automatically called when the events occur on the page.



www.codecollege.NET

What is the difference between the Write and Warn methods of the TraceContext Class?


Write - Writes the message in default colour.
Warn - writes the message in red colour.



www.codecollege.NET

How will you enable tracing in a asp.net page?


By setting the following page directive,
Trace=True


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



www.codecollege.NET

How will you filter a DataView ?


You can do that by using the property,

RowFilter



www.codecollege.NET

How will you find a control in a page and access it?


You can find any control in a page using the following method,

FindControl(controlid);



www.codecollege.NET

What are the special folders in asp.net and their purpose?

























Sno
Folder
Purpose
1 App_Code This folder is for the Non-page class files that
are compiled together to create a single assembly.
2 App_Data For the Database files used by the application.
3

App_Themes

For the Themes used by the
application.
4

Bin
For the Compiled code
used by the application


 

What is Causes Validation property for?


It is a property which determines whether the validation that has to be done by the validation control should happen or not on the button click. Default value is True.



www.codecollege.NET

What is AutoPostBack ?


It is a property which determines whether a page is posted back to the server when the value of the control changes. Applicable for controls like check box,drop-down list,radio button or text box. Default value is false.



www.codecollege.NET

LinkWithin

Blog Widget by LinkWithin

Recommended Books