Search This Blog

Saturday, November 5, 2011

How to check that a page is valid using javascript.

<input type="submit" value="Submit" onclick"ValidatePage();" />

<script type="text/javascript">

function ValidatePage() {

if (typeof (Page_ClientValidate) == 'function') {
Page_ClientValidate();
}

if (Page_IsValid) {
// do something
alert('Page is valid!');
}
else {
// do something else
alert('Page is not valid!');
}
}

</script>

Sunday, October 23, 2011

Wednesday, October 5, 2011

how to use Sql Server Profiler

Microsoft SQL Server Profiler is a graphical user interface to SQL Trace for monitoring T-SQL Statements of Database Engine. We can save and reuse the state at a later point of time.

•We can do the following using SQL Server Profiler
    ◦Create a trace
    ◦Watch the trace results as the trace runs
    ◦Store the trace results in a table
    ◦Start, stop, pause, and modify the trace results as necessary
    ◦Replay the trace results
•Use SQL Server Profiler to monitor only the events in which you are interested

How To Start SQL Profiler
>In Sql Server 2000
    Start | Run | profiler | OK
>In Sql Server 2005
    Start | All Programs | Microsoft SQL Server 2005 | Performance Tools | SQL Server Profiler.

Saturday, October 1, 2011

Integer Displaying as Hexadecimal When Debugging in Visual Studio.

If you Integers are displaying as hexadecimals (funny letters) then you've probably switched on the hexadecimal display option in your watch window.

You need to debug a project, open up the watch window: Debug > Windows > Watch 1 then right click on an entry and untick 'hexidecimal display'

Thursday, September 29, 2011

How to use GridViewDataRow with html contents.

If datasource(datatable) has html contents and bind this datasource to the gridview.
The GridView will show the data as it is in datatable.It means it will show the html content as it is.
For Example:
Your DataTable has html content "<Strong>Testing</Strong>" but gridview display same "<Strong>Testing</Strong>" instead of "Testing".

Solution:

Add the following code into gridView's Rowdatabound event.

protected void GridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
foreach (TableCell cell in e.Row.Cells)
{
cell.Text = Server.HtmlDecode(cell.Text);
}
}

Tuesday, September 27, 2011

How to swap column value of a sql table.

Create Table tmp (A varchar(10),B VARCHAR(10))


insert into tmp values('a','1')
insert into tmp values('b','2')
insert into tmp values('v','3')

Select * from tmp

output
A B
a 1
b 2
v 3

Update #tmp Set A=B, B=A

Select * from tmp
swapped output
A B
1 a
2 b
3 v

Sunday, September 25, 2011

Handler "PageHandlerFactory-Integrated" has a bad module "ManagedPipelineHandler" in its module list

This error comes when you are trying to access iis7.0 or upgraded and iis is not register for asp.net.
Solution:Register IIS with ASPNET4.0 as follows......

c:\windows\microsoft.net\framework\v4.0.30319>aspnet_regiis -i

Friday, August 19, 2011

External table is not in the expected format.

"External table is not in the expected format." typically occurs when trying to use an Excel 2007 file with a connection string that uses: Microsoft.Jet.OLEDB.4.0 and Extended Properties=Excel 8.0

Using the following connection string seems to fix most problems.

public static string path = @"C:\src\RedirectApplication\RedirectApplication\301s.xlsx";
public static string connStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=Excel 12.0;HDR=Yes;IMEX=1;";

Print Using Javascript.

function tablePrint(tblId)
{

var display_setting="toolbar=yes,location=no,directories=yes,menubar=yes,";
display_setting+="scrollbars=yes,width=750, height=600, left=100, top=25";
var lbtnPrint = document.getElementById('ctl00_CPHVmanage_FvVendorBillEntry_lbtnPrint');
lbtnPrint.style.display = 'none';
var content_innerhtml = document.getElementById(tblId).innerHTML;
var document_print = window.open("","",display_setting);
//document_print.document.open();
document_print.document.write('<html><head><title>Vendor Bill </title></head>');
document_print.document.write('<body onLoad="self.print();self.close();" >');
document_print.document.write(content_innerhtml);
document_print.document.write('</body> //document_print.print();
document_print.document.close();
lbtnPrint.style.display = 'block';
return false;
}

HTML:
<table id="tbl_display" style="text-align:left;" width="100%" cellpadding="2" cellspacing="2" border="0">
<tr>
<td align="left">
<p> Thank you valuable user for signing up.</p>
<p> We think you’ve made a bold decision, and look forward to a productive meeting.</p>
<p> Please print out a copy of this invitation - it will serve as your boarding pass on this tour. </p>
<p> For additional information, you can email <a href="mailto:someone@someone.com">someone@someone.com</a> or call -
xxx-xxx-xxxx, xxx-xxx-xxx and look for Mr. Someone.</p>
</td>
</tr>
</table>

<input type="ctl00_CPHVmanage_FvVendorBillEntry_lbtnPrint" value="Print" onclick="tablePrint('tbl_display');">

Friday, August 12, 2011

Keyword 'this' is not valid in a static property, static method, or static field initialize.

'this' object is not a static property, static method, or static field initialize , so it can not be used to call a static method.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ArnoldBaseModule
{
public class Message
{
public static string GetMessage(int ModuleId, int UserId, int AppId, int ConAppId, bool Successed, int indicator)
{
if (Successed)
{
this.GenerateMessage(ModuleId, UserId, AppId, ConAppId, Successed, indicator);
//Use below line without 'this' to call a methos instead of above............
GenerateMessage(ModuleId, UserId, AppId, ConAppId, Successed, indicator);
}
return "";
}
private static string GenerateMessage(int ModuleId, int UserId, int AppId, int ConAppId, bool Successed, int indicator)
{
return "";
}
}
}

SqlConnection.ConnectionTimeout Property.

Gets the time to wait while trying to establish a connection before terminating the attempt and generating an error.

Namespace: System.Data.SqlClient
Assembly: System.Data (in System.Data.dll)
Type: System.Int32
The time (in seconds) to wait for a connection to open. The default value is 15 seconds.

SqlCommand.CommandTimeout Property.

Property Value
Type: System.Int32
The time in seconds to wait for the command to execute. The default is 30 seconds.

Saturday, August 6, 2011

How to show div on mousehover?

Javascript Part:
<script type="text/javascript">
function Show(id) {
var div1 = document.getElementById("MainContent_div1");
div1.style.display = "block";
var ev = window.event;
var x = ev.clientX;//mouse position from left
var y = ev.clientY;//mouse position from top
div1.style.left = x;
div1.style.top = y;
}
function Hide(id) {
var div1 = document.getElementById("MainContent_div1");
div1.style.display = "none";
}
</script>


html part

<span id="MainContent_lbl1" onmouseover="javascript:Show(this);">Test <div id="MainContent_div1" style="position: absolute; z-index: 999; display: none;">
<table bgcolor="blue">
<tr>
<td>
<input name="ctl00$MainContent$txt1" type="text" id="MainContent_txt1" />
</td>
</tr>
<tr>
<td>
<input name="ctl00$MainContent$TextBox1" type="text" id="MainContent_TextBox1" />
</td>
</tr>
<tr>
<td>
<input name="ctl00$MainContent$TextBox2" type="text" id="MainContent_TextBox2" />
</td>
</tr>
<tr>
<td>
<input name="ctl00$MainContent$TextBox3" type="text" id="MainContent_TextBox3" />
</td>
</tr>
<tr>
<td>
<input name="ctl00$MainContent$TextBox4" type="text" id="MainContent_TextBox4" />
</td>
</tr>
<tr>
<td>
<input type="submit" name="ctl00$MainContent$btn1" value="Close" onclick="javascript:Hide(this);return false;" id="MainContent_btn1" />
</td>
</tr>
</table>
</div>

Friday, August 5, 2011

How to use Container.DataItemIndex?

<asp:GridView ID="gvVendorBillDtl" runat="server" AllowPaging="true" AllowSorting="true" AutoGenerateColumns="false" Width="100%" CellPadding="2" CellSpacing="0" BorderWidth="1" PageSize="5"
<Columns>

<asp:TemplateField HeaderText="Sr.No.">
<ItemTemplate>
<asp:Label ID="SrNo" runat="server" Text='<%# Container.DataItemIndex + 1 %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

Saturday, July 30, 2011

The operation has timed out.

This error come when we try to access a web service method and this method takes more than 2 minutes to response. Because IIS default timeout is 120 seconds.
To resolve this problem set the web service timeout at runtime
as below....

SheetCuttingWebService.Service objWeb;
objWeb = new UserInterfaceLayer.SheetCuttingWebService.Service();
objWeb.Timeout = 3600000(mili seconds);
dsPlate = objWeb.GetPlates(origin_id, specification, length, width, thickness, do_number, heat_no, plate_no, drawing_no, certificate_no, percentage_free, balance_wt, order_by_column, user_id, plate_id, reqLengthFrom, reqLengthTo, reqWidthFrom, reqWidthTo, IsDiscarded);

Monday, July 11, 2011

Javascript keyCode
























































































































































Key Pressed Javascript Key Code
backspace 8
tab 9
enter 13
shift 16
ctrl 17
alt 18
pause/break 19
caps lock 20
escape 27
page up 33
page down 34
end 35
home 36
left arrow 37
up arrow 38
right arrow 39
down arrow 40
insert 45
delete 46
0 48
1 49
2 50
3 51
4 52
5 53
6 54
7 55
8 56
9 57






























































































































Key Pressed Javascript Key Code
a 65
b 66
c 67
d 68
e 69
f 70
g 71
h 72
i 73
j 74
k 75
l 76
m 77
n 78
o 79
p 80
q 81
r 82
s 83
t 84
u 85
v 86
w 87
x 88
y 89
z 90
















































































































































Key Pressed Javascript Key Code
left window key 91
right window key 92
select key 93
numpad 0 96
numpad 1 97
numpad 2 98
numpad 3 99
numpad 4 100
numpad 5 101
numpad 6 102
numpad 7 103
numpad 8 104
numpad 9 105
multiply 106
add 107
subtract 109
decimal point 110
divide 111
f1 112
f2 113
f3 114
f4 115
f5 116
f6 117
f7 118
f8 119
f9 120
f10 121
f11 122
f12 123






































































Key Pressed Javascript Key Code
num lock 144
scroll lock 145
semi-colon 186
equal sign 187
comma 188
dash 189
period 190
forward slash 191
grave accent 192
open bracket 219
back slash 220
close braket 221
single quote 222

w3schools

http://wwwhttp://www.blogger.com/img/blank.gif.w3schools.com/default.asp

Wednesday, July 6, 2011

Sys.InvalidOperationException: Handler must be a function.

This exception comes when you give java script function name with parenthesis to an ajax control. e.g <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
...
....
<form id="form1" runat="server">
   
<asp:ScriptManager ID="sm1" runat="server"></asp:ScriptManager>
   
<cc1:TabContainer runat="server" ID="tbcTabContainer" OnClientActiveTabChanged="ChangeTab()"></cc1:TabContainer>
</form> Above OnClientActiveTabChanged="ChangeTab()" is not valid. Solution: Change OnClientActiveTabChanged="ChangeTab()" to OnClientActiveTabChanged="ChangeTab"

AutoCompleteExtender with Animation


<ajaxToolkit:AutoCompleteExtender runat="server" BehaviorID="AutoCompleteEx"
ID="autoComplete1" TargetControlID="txtPayorName" ServicePath="~/Public/AutoCompleteService.asmx"
MinimumPrefixLength="1" CompletionInterval="1000" EnableCaching="true" CompletionSetCount="20"
ServiceMethod="GetPayorsList" CompletionListCssClass="autocompleteCompletionListElement"
CompletionListItemCssClass="autocompleteListItem" CompletionListHighlightedItemCssClass="autocompleteHighlightedListItem"
DelimiterCharacters="">

    <Animations>

        <OnShow>
              <Sequence>  
                     <OpacityAction Opacity='0' />
                       <HideAction Visible='true'/>                                              
                        <Parallel Duration='.1'>
                                <FadeIn />
                                 <Length PropertyKey='height' StartValue='0' EndValueScript='225' />
                       </Parallel>
               </Sequence>
             </OnShow>
             <OnHide>
                    <Parallel Duration='.1'>
                           <FadeOut/>
                            <Length PropertyKey='height' StartValueScript='225' EndValue='0'/>
                     </Parallel>
               </OnHide>
    </Animations>
</ajaxToolkit:AutoCompleteExtender>

Tuesday, July 5, 2011

Excel System.Data.OleDb.OleDbException: No value given for one or more required parameter

This Error comes when Excel connection string "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\MyExcel.xls;Extended Properties="Excel 8.0;HDR=Yes;IMEX=1" " contains 'HDR=Yes' and you are using F1,F2, F3, etc in your select statement.

Solution:
if your Excel connection string contains 'HDR=Yes' then valid columns would be in the first row of the specified Worksheet (or Range). Otherwise, (HDR=No) the column names default to F1, F2, F3, etc.

Saturday, June 25, 2011

how to configure httpruntime?

<configuration>
<system.web>
<httpRuntime useFullyQualifiedRedirectUrl="true|false"
maxRequestLength="size in kbytes"
executionTimeout="seconds"
minFreeThreads="number of threads"
minFreeLocalRequestFreeThreads="number of threads"
appRequestQueueLimit="number of requests"
versionHeader="version string"/>
</configuration>
</system.web>

HTML: What does &#39; mean?

&#39; is html encoding for apostrophe(')

Whenever we type an apostrophe(') the ecards(html) replaces it with &#39;. So &#39; is the Html representation for apostrophe(').

For Example: Html will convert Rahul's into Rahul&#39;s.

Wednesday, June 15, 2011

How to Encode and Decode a QueryString using c#?

Use HttpUtility.UrlEncode(string QueryString) to encode a url or query string
e.g the actual url is "http://192.168.45.48/encoding/encode.aspx?crdl1=esos.{€h579". This url has some special character "{€". If you want to encode this url do as

HttpUtility.UrlEncode("http://192.168.45.48/encoding/encode.aspx?crdl1=esos.{€h579")
output will come as "http://192.168.45.48/encoding/encode.aspx?crdl1=esos.%7B%E2%82%ACh579".

And you can decode this encoded url using following code:
HttpUtility.UrlDecode("http://192.168.45.48/encoding/encode.aspx?crdl1=esos.%7B%E2%82%ACh579")

the output will come as "http://192.168.45.48/encoding/encode.aspx?crdl1=esos.{€h579"

Tuesday, May 17, 2011

Cannot start service from the command line or a debugger. A Windows Service must first be installed (using installutil.exe) and then started with ...

In order to run a Windows Service, do the following:

1) Build your Windows Service Project in VS.NET to generate its exe.

2) Run the Visual Studio.NET 2003 Command Prompt; OR On the DOS prompt, go to C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322 (Directory path may vary).

3) Use the following command to run your Windows Service. (Subsitute the items in [...] according to your local app.)

installutil C:\[YourAppPath]\[AppName]\[Debug Release]\[AppName].exe

system.componentmodel.win32exception: no mapping between account names and security ids was done

When installing a windows service using installutil, it prompts for username & password, and after providing the username and the password it gives the following error:

system.componentmodel.win32exception: no mapping between account names and security ids was done

To resolve this problem add the below line to the ProjectInstaller.cs file (in InitializeComponent)
this.serviceProcessInstaller1.Account = System.ServiceProcess.ServiceAccount.LocalSystem;

Wednesday, March 30, 2011

sys.ArgumentTypeException object of type 'object' cannot be converted to type 'Number'

This error comes when you are using ajax control on your page and also having some java script codes which include the built-in java script function with invalid arguments Or user defined function override the built-in function with invalid arguments.
e.g

function Number() {
var evnt = window.event;

if (parseInt(evnt.keyCode) >= 48 && parseInt(evnt.keyCode) <= 57) {
evnt.keyCode = evnt.keyCode;
return true;
}
else {
evnt.keyCode = 8;
return false;
}
}
Above function Number() is the actually built-in function with some arguments but here it is used as a user defined function width no argument.

Note: Change the function name or give the appropriate arguments to the function to resolved the above error.

Wednesday, March 16, 2011

How to drop sql connection

USE master
GO

ALTER DATABASE database name
SET OFFLINE WITH ROLLBACK IMMEDIATE
ALTER DATABASE database name
SET ONLINE

Wednesday, March 2, 2011

Tuesday, January 18, 2011

How to import data from txt file to sql table

create table #tmp (val1 int, val2 int, val3 int)

BULK
INSERT #tmp
FROM '\\192.168.2.25\c$\test.txt'
WITH
(
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n'
)

select * from #tmp