Sunday, January 6, 2013

How to get/set a Control’s position on client side?

Microsoft AJAX Library provides a bunch of facilities to manipulate the HTML element on client side, including getting and setting the position of an element.

For example:
To get a Panel's current position on the client side, we can use $common.getLocation(DOM Element) function.
//Get DOM Element with $get() function. 
var el = $get('<%=Panel1.ClientID%>');   
//Get its position.  
var newLocation = $common.getLocation(el);
To set its position:

//Create the new position.
var newLocation = new Sys.UI.Point(x-position,y-position);
//Move the Panel to the destination.
$common.setLocation(Panel, newLocation); 
Sometimes, 

Monday, September 17, 2012

How to solve error: 404.2 The page you are requesting cannot be served

Problem: 
I get the error while trying to visit home page of a deployed asp.net 4 application in IIS7: 404.2 The page you are requesting cannot be served because of the ISAPI and CGI Restriction list settings on the Web server.

How can I solve this issue?

 Solution:
This error occurs because the requested ISAP(Internet Server API) and/or CGI(Common Gateway Interface) resource is restricted on the computer that is running IIS 7. After installing .NET Framework 4.0 on a machine there is a few configuration changes you need to do to IIS in order to get a ASP.NET 4.0 page running.

To resolve this issue you have to follow steps mentioned below:

1. Open IIS and Click on the sever name.
2. In Feature View Double click "ISAPI and CGI Restrictions"



3. Select ASP.Net V4 and click Allow in action panel. It will be set to Allowed.

Now your application should run.


Tuesday, September 4, 2012

How to call server side a direct method from ext.net gridpanel?


In ext.net you can call server side direct method from your client side code. This is an excellent way to doing jobs on server side from client side java script function and grid panel, button or other controls. Here we will see how we can do this job done in a grid panel.
In the following code snippet will call a direct method against an action in a grid panel action column. Also we will pass some arguments from our grid to direct method that we require for data manipulation on server side.
Let see code for grid panel:
<ext:GridPanel ID="gpList" runat="server" StripeRows="true" Title="BO List" AutoExpandColumn="name"
                                    Collapsible="true" AnchorHorizontal="100%" Height="350">
                                    <Store>
                                        <ext:Store ID="gpListStore" runat="server" OnRefreshData="gpListStore_RefreshData"
                                            OnSubmitData="gpListStore_SubmitData">
                                            <Reader>
                                                <ext:JsonReader IDProperty="cno">
                                                    <Fields>
                                                        <ext:RecordField Name="dividendyear" />
                                                        <ext:RecordField Name="declareid" />
                                                        <ext:RecordField Name="wno" />
                                                        <ext:RecordField Name="name" />
                                                        <ext:RecordField Name="boid" />
                                                        <ext:RecordField Name="shares" />
                                                        <ext:RecordField Name="dividendM" />
                                                        <ext:RecordField Name="taxrate" />
                                                        <ext:RecordField Name="taxamt" />
                                                        <ext:RecordField Name="netamt" />
                                                        <ext:RecordField Name="actionid" />
                                                        <ext:RecordField Name="status" />
                                                    </Fields>
                                                </ext:JsonReader>
                                            </Reader>
                                        </ext:Store>
                                    </Store>
                                    <ColumnModel ID="ColumnModel1" runat="server">
                                        <Columns>
                                            <ext:RowNumbererColumn />
                                            <ext:Column ColumnID="cdeclareid" Header="Declare Id" DataIndex="declareid" Width="70" />
                                            <ext:Column ColumnID="cdividendyear" Header="Year" DataIndex="dividendyear" Width="50">
                                            </ext:Column>
                                            <ext:Column ColumnID="cBoid" Header="Boid" DataIndex="boid" Width="130" />
                                            <ext:Column ColumnID="cname" Header="Name" DataIndex="name" />
                                            <ext:Column ColumnID="cshares" Header="Shares" DataIndex="shares" Width="50" />
                                            <ext:Column ColumnID="cdividendM" Header="Dividend" DataIndex="dividendM" Width="50" />
                                            <ext:Column ColumnID="ctaxrate" Header="Tax Rate" DataIndex="taxrate" Width="50" />
                                            <ext:Column ColumnID="ctaxamt" Header="Tax Amt" DataIndex="taxamt" Width="50" />
                                            <ext:Column ColumnID="cnetamt" Header="Net Amt" DataIndex="netamt" Width="50" />
                                            <ext:Column ColumnID="cStatus" Header="Status" DataIndex="status" />
                                            <ext:CommandColumn Header="Action" Width="90">
                                                <Commands>
                                                    <ext:GridCommand Icon="ApplicationViewDetail" CommandName="ViewDetail">
                                                        <ToolTip Text="View Detail" />
                                                    </ext:GridCommand>
                                                    <ext:CommandSeparator />
                                                    <ext:GridCommand Icon="AsteriskRed" CommandName="Action">
                                                        <ToolTip Text="Action" />
                                                    </ext:GridCommand>
                                                    <ext:CommandSeparator />
                                                    <ext:GridCommand Icon="Connect" CommandName="Communication">
                                                        <ToolTip Text="Communication with people." />
                                                    </ext:GridCommand>
                                                </Commands>
                                            </ext:CommandColumn>
                                        </Columns>
                                    </ColumnModel>
                                    <SelectionModel>
                                        <ext:CheckboxSelectionModel ID="CheckboxSelectionModel1" runat="server" />
                                    </SelectionModel>
                                    <BottomBar>
                                        <ext:PagingToolbar ID="PagingToolBar1" runat="server" PageSize="10" />
                                    </BottomBar>
                                    <Listeners>
                                        <Command Handler="Ext.net.DirectMethods.ExecuteActionCommand(command, record.data.wno, record.data.declareid, record.data.boid);" />
                                    </Listeners>
                                    <DirectEvents>
                                        <AfterEdit OnEvent="gpList_AfterEdit">
                                            <EventMask ShowMask="true" Target="This" />
                                            <ExtraParams>
                                                <ext:Parameter Name="field" Value="e.field" Mode="Raw" />
                                                <ext:Parameter Name="id" Value="e.record.id" Mode="Raw" />
                                                <ext:Parameter Name="record" Value="e.record.data" Mode="Raw" Encode="true" />
                                            </ExtraParams>
                                        </AfterEdit>
                                    </DirectEvents>
                                </ext:GridPanel>


Direct method is called using listener in ext.net which always woks at client side.
<Listeners>
          <Command Handler="Ext.net.DirectMethods.ExecuteActionCommand(command, record.data.wno, record.data.declareid, record.data.boid);" />
</Listeners>


Here in Action column we have three action commands:
1.  ViewDetail
2.  Action
3.  Communication
These commands will pass to parameter command and on server side we will decide which action actually performed. Server side code is here:
[DirectMethod]
    public void ExecuteActionCommand(string command, string wno,  string declareid, string boid)
    {
        if (command == "ViewDetail")
        {
            //Display bo holder detail info
            var win = new Window
            {
                ID = "BOWindow",
                Title = "Bo Detail",
                Width = Unit.Pixel(800),
                Height = Unit.Pixel(380),
                Modal = true,
                Collapsible = true,
                Maximizable = false,
                Hidden = false,

            };

            win.AutoLoad.Url = "~/BoMasterDetails.aspx?boid=" + boid + "&declareid=" + declareid;
            win.AutoLoad.Mode = LoadMode.IFrame;

            win.Render(this.Form); win.Dispose();
        }
        else if (command == "Action")
        {
            var win = new Window
            {
                ID = "ActionWindow",
                Title = "Corporate Action",
                Width = Unit.Pixel(800),
                Height = Unit.Pixel(550),
                Modal = true,
                Collapsible = true,
                Maximizable = false,
                Hidden = false,

            };

            win.AutoLoad.Url = "~/ActionLogEntryPopup.aspx?wno=" + wno + "&boid=" + boid + "&declareid=" + declareid;
            win.AutoLoad.Mode = LoadMode.IFrame;

            win.Render(this.Form); win.Dispose();
        }
        else if (command == "Communication")
        {
            dividend div = new dividendBLL().dividend_GetAll_By_wno(wno).FirstOrDefault();
            var win = new Window
            {
                ID = "CommWindow",
                Title = "Communication",
                Width = Unit.Pixel(800),
                Height = Unit.Pixel(550),
                Modal = true,
                Collapsible = true,
                Maximizable = false,
                Hidden = false,

            };

            win.AutoLoad.Url = "~/CommunicationLogEntryPopup.aspx?wno=" + wno + "&boid=" + boid + "&declareid=" + declareid;
            win.AutoLoad.Mode = LoadMode.IFrame;

            win.Render(this.Form); win.Dispose();
        }
    }

How to display a popup dynamically in ext.net?


Here I will show you quick tips on how you can create a dynamic popup control in your ext.net application.
Look at the following server side ext.net code snippet:
            var win = new Window
            {
                ID = "CommWindow",
                Title = "Communication",
                Width = Unit.Pixel(800),
                Height = Unit.Pixel(550),
                Modal = true,
                Collapsible = true,
                Maximizable = false,
                Hidden = false,

            };

            win.AutoLoad.Url = "~/CommunicationLogEntryPopup.aspx?wno=" + wno + "&boid=" + boid + "&declareid=" + declareid;
            win.AutoLoad.Mode = LoadMode.IFrame;

            win.Render(this.Form); win.Dispose();

First create a window and define all its properties and load your page into the window and IFrame.
Hope this will help you guys. 

Wednesday, June 1, 2011

Making ViewState Secure

One of the most common ways to store information is in view state. View State uses hidden
field that ASP.Net automatically inserts in the rendered HTML of a web page. View state
information is stored in a single jumbled string that looks like this:
As this value isn’t formated as clear text, many ASP.Net programmers assume that
their view state data is encrypted. Actually, view state information is simply patched
together in memory and converted to a Base54 string which is a special type of string that
is always acceptable in an HTML document because it does not include any special character.
A clever hacker could reverse-engineer this string and examine your view state data
in a matter of second.
To make your secure data temperproof you have to use encryption enabled. You can turn on
encryption for an individual page using the ViewStateEncryptionMode property of the page
directive:

Thursday, January 6, 2011

Count total working days between two days in T-SQL

Create a user defined scalar function:

CREATE FUNCTION [dbo].[udf_GetWorkingDays](@StartDate DATETIME,@EndDate DATETIME)
RETURNS INT
AS
BEGIN

DECLARE @CurDate DATETIME
DECLARE @i INT
DECLARE @days INT

set @i=1
set @days=0
while @i<=(DATEDIFF(dd, @StartDate, @EndDate))
begin
      set @CurDate=dateadd(day,@i, @StartDate)
      if(DATENAME(dw, @CurDate) != 'Friday' and DATENAME(dw, @CurDate) != 'Saturday')
      begin
            set @days=@days+1
      end

      set @i=@i+1
end

RETURN @days
END



Let's test now with following query:
 
select dbo.udf_GetWorkingDays('01/01/2011','01/31/2011') as TotalWorkingDays

 Result is: 22

Hope this will help others.