Thursday, October 29, 2009

What is Difference between ScriptManager & ScriptManagerProxy

ScriptManager
A server control that makes script resources available to the browser, including the Microsoft AJAX Library and the functionality that enables partial-page rendering.



ScriptManagerProxy
A server control that enables nested components to add script and service references if the page already contains a ScriptManager control.
Read More

What is Use of Scriptmanager in asp.net AJAX

The ScriptManager control manages client script for Microsoft ASP.NET AJAX pages. By default, the ScriptManager control registers the script for the Microsoft AJAX Library with the page. This enables client script to use the type system extensions and to support features such as partial-page rendering and Web-service calls.

Background
When a page contains one or more UpdatePanel controls, the ScriptManager control manages partial-page rendering in the browser. The control interacts with the page life cycle to update the parts of the page that are inside UpdatePanel controls. For more information, see Partial-Page Rendering Overview.

The EnablePartialRendering property of the ScriptManager control determines whether a page participates in partial-page updates.


ScriptManager is a server-side control that sits on your Web Form and enables the core of ASP.NET AJAX. Its primary role is the arbitration of all other ASP.NET AJAX controls on the Web Form and the addition of the right scripting libraries to the Web browser so that the client portion of ASP.NET AJAX can function. Often you will find yourself using the ScriptManager to register other controls, Web services, and client scripts.
As a server-side control, ScriptManager reacts to events in the ASP.NET page lifecycle and uses those events to coordinate the activities of all the controls, options, and code employed by ASP.NET AJAX. ScriptManager will hook a particular event, get notified when it occurs, and configure a few settings depending on the environment; this process will repeat itself several times through the rendering cycle of your ASP.NET page. The settings it configures, however, are often the exact settings needed to make your use of ASP.NET AJAX seamless.

Why Use the ScriptManager Control

You must use a ScriptManager control on a page to enable the following features of ASP.NET AJAX:

Client-script functionality of the Microsoft AJAX Library, and any custom script that you want to send to the browser. For more information, see ASP.NET AJAX and JavaScript.

Partial-page rendering, which enables regions on the page to be independently refreshed without a postback. The ASP.NET AJAX UpdatePanel, UpdateProgress, and Timer controls require a ScriptManager control to support partial-page rendering.

JavaScript proxy classes for Web services, which enable you to use client script to access Web services by exposing Web services as strongly typed objects.

JavaScript classes to access ASP.NET authentication and profile application services.

Enabling Partial-Page Rendering

When a page contains one or more UpdatePanel controls, the ScriptManager control manages partial-page rendering in the browser. The control interacts with the page life cycle to update the parts of the page that are inside UpdatePanel controls. For more information, see Partial-Page Rendering Overview.

The EnablePartialRendering property of the ScriptManager control determines whether a page participates in partial-page updates. By default, the EnablePartialRendering property is true. Therefore, partial-page rendering is enabled by default when you add a ScriptManager control to the page. For information about how to use the UpdatePanel control with the ScriptManager control, see Introduction to the UpdatePanel Control and Creating a Simple ASP.NET Page with Multiple UpdatePanel Controls.

Handling Errors

During partial-page rendering, you can handle errors by doing the following:

Set the AllowCustomErrorsRedirect property, which determines how the custom error section of the Web.config file is used when an error occurs during an asynchronous postback.

Handle the ScriptManager control's AsyncPostBackError event, which is raised when there is a page error during an asynchronous postback.

Set the AsyncPostBackErrorMessage property, which is the error message that is sent to the browser.

Using Type System Extensions

Microsoft AJAX Library adds type-system extensions to JavaScript that provide namespaces, inheritance, interfaces, enumerations, reflection, and helper functions for strings and arrays. These extensions provide functionality in client script that is like that of the .NET Framework. They enable you to write ASP.NET 2.0 AJAX Extensions applications in a structured way that improves maintainability, makes it easier to add features, and makes it easier to layer functionality. Adding a ScriptManager control to an ASP.NET Web page automatically includes the type-system extensions so that you can use the library in client script.

Registering Custom Script

Use the ScriptManager control to manage resources that you have created for controls that participate in partial-page updates. Resources include scripts, styles, hidden fields, and arrays. The Scripts collection of the ScriptManager control contains a ScriptReference object for each script that is available to the browser. You can specify the scripts declaratively or programmatically.

The ScriptManager control also exposes registration methods that you can use to manage client script and hidden fields programmatically. When you are registering script or hidden fields that support partial-page updates, you must call registration methods of the ScriptManager control. (To register scripts that are not needed for partial-page updates, you use methods of the ClientScriptManager class.)


Registering Web Services

The ScriptManager control's Services collection contains a ServiceReference object for each Web service that is registered with the ScriptManager control. The ASP.NET AJAX framework generates a client proxy object for each ServiceReference object in the Services collection. The proxy classes and their strongly typed members simplify using Web services from client script.
You can programmatically add ServiceReference objects to the Services collection to register Web services at run time.

Using Authentication and Profile Services from Client Script

The Microsoft AJAX Library includes proxy classes for calling the ASP.NET 2.0 forms authentication and profile application services directly from JavaScript. If you want to use a custom authentication service, you can register it using the ScriptManager control.

The ScriptManagerProxy Class

Only one instance of the ScriptManager control can be added to the page. The page can include the control directly, or indirectly inside a nested component such as a user control, content page for a master page, or nested master page. In cases where a ScriptManager control is already on the page but a nested or parent component needs additional features of the ScriptManager control, the component can include a ScriptManagerProxy control. For example, the ScriptManagerProxy control enables you to add scripts and services that are specific to nested components.
Read More

Friday, October 23, 2009

What is the CHECK constraint in SQL Server?

Business rule validation can be applied to a table by using CHECK constraint. CHECK constraint must be specified as a logical expression that evaluates either to TRUE or FALSE.
A CHECK constraint takes longer to execute as compared to NOT NULL, PRIMARY KEY, FOREIGN KEY or UNIQUE constraints. Thus CHECK constraint must be avoided if the constraint can de defined using NOT NULL, PRIMARY KEY, FOREIGN KEY constraints.
Read More

What are the types of constraints in SQL Server?

There are three types of constraints in SQL Server -
1. Domain Constraint - deals with one are more columns.
2. Entity Constraint - are all about individual rows.
2. Referential Integrity Constraint - are created when a value in one column must match the value in another column - in either the same table or in a different table.
Read More

What is the limit of a row n SQL Server?

A row can be up to 8KB.
Read More

What is the maximum number of columns in a row in SQL Server?

1024 columns.
Read More

What is the DEFAULT constraint in SQL Server?

A DEFAULT constraint, like all constraints, becomes an integral part of the table definition. It defines what to do when new row is inserted that does not include data for the column on which you have defined the DEFAULT constraint. You can either define it as a literal value(like default salary to zero or UNKNOWN for a string column) or as one of several values such as GETDATE().
The main things to understand about a DEFAULT constraint are -

1. DEFAULTs are only used in INSERT statements- They are ignored for UPDATE and DELETE statements.
2. If any value is supplied in the INSERT then the default is not used.
3. If no values supplied the default will always be used.
Read More

How to find out column names and their datatypes in a given table using a query in SQL Server?

Using the table tablename, write the query as follows -
Select * from information_schema.columns where table_name = tablename
Read More

What is the DEADLOCK ?

A deadlock is a situation in which two transactions conflict with each other and the only resolution is to cancel one transaction.
Read More

What is a Subquery ?

A Subquery is a normal T-SQL query that is nested inside another query. They are created using parentheses when you have a SELECT statement that serve as the basis for the either part of the data or the condition in another query.
Subqueries are generally used to fill one of couple of needs -

1. Break a query up into a series of a logical steps.
2. Provide a listing to be the target of a WHERE clause together with [IN|ESISTS|ANY|ALL].
3. TO provide a lookup driven by each individual record in a parent query.
Eg.
SELECT SelectList FROM SomeTable WHERE SomeColumn = (SELECT SingleColumn FROM SomeTable WHERE Condition that results in only one row returned)
Read More

What is the EXISTS operator in SQL Server ? OR What is the EXISTS keyword in SQL Server ?

When you use EXISTS, you do not really returned data - instead you return a simple TRUE/FALSE regarding the existence of data that meets the criteria established in the query that the EXISTS statement is operated against.
EXISTS simply test whether the inner query returns any row. If it does, then the outer query proceeds, if not, the outer query does not executes, and the entire SQL statement returns nothing.

The EXISTS condition is considered "to be met " if the subquery returns at least one row.

The syntax for EXISTS condition is -
SELECT columns FROM sometable WHERE EXISTS (subquery)
Read More

How to find nth highest salary from Employee table in SQL Server?

SELECT TOP 1 salary FROM (SELECT DISTINCT TOP n salary FROM employee ORDER BY salary DESC) a ORDER BY salary
Read More

How to convert timestamp data to date data (datetime datatype) in SQL Server?

The name timestamp is a little misleading. Timestamp data has nothing to do with dates and times and can not be converted to date data. A timestamp is a unique number within the database and is equivalent to a binary(8)/varbinary(8) datatype. A table can have only one timestamp column. Timestamp value of a row changes with every update of the row. To avoid the confusion, SQL Server 2000 introduced a synonym to timestamp, called rowversion.
Read More

What is the IDENTITY property in SQL Server?

The IDENTITY property enables you to use system generated values in your tables column. It is similar to the auto number datatype in MS ACCESS. You are allowed a single column in each table with the IDENTITY property. Typically, IDENTITY column generates system assigned keys. To enforce entity integrity, you must uniquely identify each row in a table. If no natural column or set of column does this, you might went to create an IDENTITY column.
You can use the IDENTITY property if the column to which it is being assigned is an integer or compatible with an integer. Therefore you can use the following datatypes - tinyint, bigint, smallint, numeric, integer, decimal.

You can use numeric and decimal only if they have scale of 0 (zero). It must also not allowed to NULL.
Read More

What is the CASCADE action in SQL Server?

By default, you can not delete a record or update the referenced column in a referenced table if that record is referenced from the dependent table. If you want to be able to delete or update such records, then you need to set up a CASCADE action for the delete and/or update.
Read More

What is the FOREIGN KEY in SQL Server?

FOREIGN KEYs are both a method of ensuring data integrity and a manifestation of the relationships between tables. When you add a FOREIGN KEY to a table, you create a dependency between the table for which you define the FOREIGN KEY (the referencing table) and the table your FOREIGN KEY references (the referred table). After adding a FOREIGN KEY, any record you insert into the referencing table must have a matching record in the referenced column(s) of the referenced table, or the value of the FOREIGN KEY column(s) must be set to NULL.
Read More

What is the use of CASCADE CONSTRAINTS?

When this clause is used with the DROP command, a parent table can be dropped even when a child table exists.
Read More

Get Current System Date Format

To get short date pattern of your system:
messagebox.show(System.Globalization.CultureInfo.CurrentCulture
.DateTimeFormat.ShortDatePattern())

To get long date pattern of your system:
messagebox.show(System.Globalization.CultureInfo.CurrentCulture.
DateTimeFormat.LongDatePattern())
Read More

Change Format of Date in VB.NET

Dim departDate As Date
departDate = Date.Now
Dim d As String = Format(departDate, "dd/MM/yyyy")
MsgBox(d)
'Above Example shows how to convert date format according to our requirements.
Read More

Tuesday, October 20, 2009

Restricting numeric entries only in a DataGridView column

At times we have a requirement where we need to restrict the user to enter only numbers in a column of a DataGridView to achieve this we need to use EditingControlShowing event of DataGridView, this event is new in .Net framework 2.0 and it occurs when a control for editing a cell is showing. Following sample shows a implementation of it:

private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
if ((int)(((System.Windows.Forms.DataGridView)(sender)).CurrentCell.ColumnIndex) == 1)
{
e.Control.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.TextboxNumeric_KeyPress);

}
}

private void TextboxNumeric_KeyPress(object sender, KeyPressEventArgs e)
{
Boolean nonNumberEntered;

nonNumberEntered = true;

if ((e.KeyChar >= 48 && e.KeyChar <= 57) || e.KeyChar == 8)
{
nonNumberEntered = false ;
}

if (nonNumberEntered == true)
{
// Stop the character from being entered into the control since it is non-numerical.
e.Handled = true ;
}
else
{
e.Handled = false;
}

}
Read More

Tuesday, October 13, 2009

Transposing Column to Row Through Select Query

My student Mr. Bhupendra Asked me that how can i show values of my columns of table as a ROW. To do so: (we also require such query while creating cross-tab report
lets we have following table:

CREATE TABLE [vehical_type](
[unqid] [uniqueidentifier] primary key,
[vname] [varchar](100) NULL
)

we can get our desired result from below query:
-- It will be better to create Stored Procedure of it.
declare @st varchar(max)
set @st='create table tmp ('
-- instead of taking normal table we can take temporary table by using #tmp
select @st = @st + ' temp' + convert(varchar,ROW_NUMBER() OVER(ORDER BY vname )) + ' varchar(max),' from vehical_type order by vname
set @st = left(@st,len(@st)-1) + ');'
--exec(@st)
--select @st
set @st= @st + 'insert into tmp values ('
select @st = @st + '''' + CONVERT(varchar(max), unqid) + ''',' from vehical_type
set @st = left(@st,len(@st)-1) + ');'

set @st= @st + 'insert into tmp values ('
select @st = @st + '''' + vname + ''',' from vehical_type
set @st = left(@st,len(@st)-1) + ');'
--select @st
exec(@st)
select * from tmp
drop table tmp
Read More

Friday, October 9, 2009

How to set required field validator for dropdownlist

My colleague Sweta asked me to how to set required field validator for doopdownlist.
so to set required field validator for doopdownlist we need to follow these steps.

1. let your dropdown list in such format that first item of it is "--Select--" as in example give below.

2. if your valumember is integer type then set value '0' of valuemamber
for "--Select--"

3. take required field validator and select your dropdownlist as control to validate and in field "Initial Value" enter '0' (without single quotes)

Note: if you are using GUID (uniqueidentifier) or any other type of value as valuemember of dropdownlist then place value of "-- select--" in "Initial Value" field of required field validator.

example:
< asp:DropDownList ID="DropDownList1" runat="server" Height="37px" Width="191px" >
< asp:ListItem Value="0" >Select < /asp:ListItem >
< asp:ListItem >--Select-- < /asp:ListItem >
< asp:ListItem >bb < /asp:ListItem >
< asp:ListItem >cc < /asp:ListItem >
< asp:ListItem >dd < /asp:ListItem >
< /asp:DropDownList >
< asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="DropDownList1" ErrorMessage="RequiredFieldValidator"
InitialValue="0" > < /asp:RequiredFieldValidator >
Read More

Tuesday, October 6, 2009

How to implement keyword "Limit" like functionality in MS SQL Server

select * from mytable limit 10, 20

the equivalent in MS SQL Server would be:

select top 20 * from mytable where pk not in (select top 10 pk from mytable order by pk) order by pk
Read More

Evaluate Rows one by one

through qry written below we will get 1 record at a time and in random order.
SELECT TOP 1 * FROM TabCountryMast ORDER BY newid()
Read More

Thursday, October 1, 2009

Create Control at runtime using JavaScript

through code written below we can create control at runtime using javascript



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

< !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 >
< script type="text/javascript" >
function addElement() {
var ni = document.getElementById('myDiv');
var numi = document.getElementById('theValue');
var num = (document.getElementById('theValue').value - 1) + 2;
numi.value = num;
var newdiv = document.createElement('div');
var divIdName = 'my' + num + 'Div';
newdiv.setAttribute('id', divIdName);
newdiv.innerHTML = "Element Number " + num + " has been added! < a href=\"javascript:;\" onclick=\"removeElement(\'" + divIdName + "\')\" >Remove the element "" + divIdName + ""< /a >";

ni.appendChild(newdiv);
}
function removeElement(divNum) {
var d = document.getElementById('myDiv');
var olddiv = document.getElementById(divNum);
d.removeChild(olddiv);
}

< /script >
< /head >
< body >
< form id="form1" runat="server" >
< div >
< input type="hidden" value="0" id="theValue" / >
< p >< a href="javascript:;" onclick="addElement();" >Add Some Elements< /a >< /p >
< div id="myDiv" > < /div >

< /div >
< /form >
< /body >
< /html >
Read More
Powered By Blogger · Designed By Seo Blogger Templates