Search

Nov 28, 2007

How to know page validity from java script

Hello All,

I was having one requirement which is as follows.

- Once you click on submit button, the button must be disabled
- All the validator should work properly then and only then button get disabled [obvious thing]
- And the page needs to be submitted back to server as well.

I was looking for the method where I can find the page valid property or value which allow me to do what I want.

There is a property Page_IsValid in java script which let me know the validity of page. But it will always set to false first time.

So I found the solution which help me to fulfill my requirement.

Have a look at following code

<script language="javascript" type="text/javascript">

function btnSaveClientClick(objBtn)
{
var isPageValid = Page_ClientValidate();
if(isPageValid)
{
objBtn.disabled = true;
__doPostBack(objBtn.name,'');
}
}

</script>

This is the server side control [submit button]

<asp:Button ID="btnSave" runat="server" SkinID="button_plain" OnClientClick="javascript:return btnSaveClientClick(this);" Text="Save" OnClick="btnSave_Click" />

How it works:

- On client click of save button btnSaveClientClick() method get executed with single parameter this which is button itself.
- Page_ClientValidate() method used for checking client site validation, will return true or false.
- objBtn.disabled, will disable the button because objBtn is reference to our Save Button
- And last need to postback to server, so call __doPostBack(objBtn.name,'');

That's it!

Oct 22, 2007

Web service architecture

Hello Friends,

What is webservice? What is WSDL? How it works?? and many more....

I found all the answere, its really nice topic where you can find all the answers.

Have a look at this Web service architecture delicios.

Regular Expression problem???

Hello friends,

I found good link which has almost all required regular expresions, have a look at this Regular Expressions delicios.

Sep 20, 2007

Threading in C#

C# supports parallel execution of code through multithreading. A thread is an independent execution path, able to run simultaneously with other threads.

To know how its working, when to use thread etc. have a look at 'delicios'

Sep 12, 2007

Display images Directly from Memory

Hello Friends,

I was looking for functionality in which I just need to throw jpg file after changing it into memory.

One way is, save it to hard drive and then use it as target of some img tag. But this is not a good idea, so searched for such kind of logic where I can directly throw the image to client.

I used following code


//Load the bitmap image
System.Drawing.Bitmap objBitMapOriginal = new System.Drawing.Bitmap(strImagePath);
//Change the bitmap image
System.Drawing.Bitmap = ScaleAndModifyImage(objBitMapOriginal);
//Save it to response
Bitmap.Save(Response.OutputStream, ImageFormat.Gif);


But this has some problem as images saved in OutputStream I cant show any other literals or data on the same response.

Then I found a solution, First store the image in session and dynamically sets the src of image which at the end pointing to same page, on requesting that image src it throws the image which is in memory and after finishing work just flush the session.

Its fairly simple, have a look at the delicious. You can also find the code.

Sep 4, 2007

How to expire previous page

Hello all,

This is the normal problem we all are facing in Web application.

Problem comes when user use back button of browser and application start malfunctioning.

Just add following code in page load

Response.Buffer = true;
Response.ExpiresAbsolute = DateTime.Now.Subtract(new TimeSpan(0, 0, 2));
Response.Expires = 0;
Response.CacheControl = "no-cache";

Aug 21, 2007

Different Options for Importing Data into SQL Server

Hello all,

I was having problem in getting data from different server, a hugh data millions of records that i have to import.

I tried lots of methods but its very difficult to get it done.

I found some solution for such hugh task.

Have a look @ Different Options for Importing Data into SQL Server.

Aug 16, 2007

Forms Authentication in ASP.NET 2.0

Hello all,

I come accross good link, which explain you the forms based authentication.

Have a look at delicious Forms Authentication in ASP.NET 2.0

Jul 26, 2007

Can you call private members from a different class?

Is it possible to access private method in a class?

I think the OO funda says no|never, you cant access.

But .NET term Reflection is providing such functionality.

Whoooppssss these circumstances breaking a OO rule.

Read more: I have delicious You can call private members from a different class.

Jun 20, 2007

Design Guidelines for Class Library Developers

The .NET Framework's managed environment allows developers to improve their programming model to support a wide range of functionality. The goal of the .NET Framework design guidelines is to encourage consistency and predictability in public APIs while enabling Web and cross-language integration. It is strongly recommended that you follow these design guidelines when developing classes and components that extend the .NET Framework. Inconsistent design adversely affects developer productivity. Development tools and add-ins can turn some of these guidelines into de facto prescriptive rules, and reduce the value of nonconforming components. Nonconforming components will function, but not to their full potential.

These guidelines are intended to help class library designers understand the trade-offs between different solutions. There might be situations where good library design requires that you violate these design guidelines. Such cases should be rare, and it is important that you provide a solid justification for your decision. The section provides naming and usage guidelines for types in the .NET Framework as well as guidelines for implementing common design patterns.

Read more: I have delicious Design Guidelines for Class Library Developers.

What is the difference between const and static readonly?

The difference is that the value of a static readonly field is set at run time, and can thus be modified by the containing class, whereas the value of a const field is set to a compile time constant.

In the static readonly case, the containing class is allowed to modify it only

· in the variable declaration (through a variable initializer)
· in the static constructor (instance constructors, if it's not static)

static readonly is typically used if the type of the field is not allowed in a constdeclaration, or when the value is not known at compile time.

Instance readonly fields are also allowed.

Remember that for reference types, in both cases (static and instance) the readonly modifier only prevents you from assigning a new reference to the field. It specifically does not make immutable the object pointed to by the reference.


class Program
{
public static readonly Test test = new Test();

static void Main(string[] args)
{
test.Name = "Program";
test = new Test(); // Error: A static readonly field cannot be assigned to (except in a static constructor or a variable initializer)
}
}


class Test
{
public string Name;
}

On the other hand, if Test were a value type, then assignment to test.Name would be an error.

Jun 14, 2007

Create .NET documentation with Microsoft's Sandcastle

Hello all,

This is post for developers who are using xml comments.

The .NET Framework allowed C# developers to use XML-style comments in their code. This feature was added to VB.NET with version 2.0. The compiler can use these comments to generate basic technical documentation. The end result of using the XML commenting feature is a large XML file that is less than user friendly

How to get Sandcastle



The latest version of Sandcastle is available via href="http://www.microsoft.com/downloads/details.aspx?FamilyId=E82EA71D-DA89-42EE-A715-696E3A4873B2&displaylang=en">Microsoft's
March 2007 Community Technology Preview
. You may install and run it on
Windows Server 2003 or Windows XP Service Pack 2. It requires the href="http://msdn2.microsoft.com/en-us/netframework/aa731542.aspx
">.NET
Framework 2.0
, as well as the href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/htmlhelp/html/hwMicrosoftHTMLHelpDownloads.asp">HTML
Help Workshop
. Once the prerequisite software is installed, you can install
the Sandcastle tool.



I also have delicious Create .NET documentation with Microsoft's Sandcastle .

Implement full text search using Stored procedures

Hello friends,

While working with Full-Text search, I come to situation where I have to write script which creates the catalog, enable it and start population on it.

Then I found there are stored procedures in master database only, which can usefull to craete, enable and populate the Full-Text Catalog in SQL Server.

Have a look at Implement full text search using Stored procedures.

Look at Help With Full-Text Catalogs - Stored Procedures are available too.

Jun 11, 2007

Problem with IIS??

Hello,

I found many of .NET developer are having problem in configuring IIS specially IIS 7.

Have a look at this delicious, it helps you lots when you stuck-up in IIS configuration.

Jun 9, 2007

What is Microsoft Silverlight

Microsoft® Silverlight™ is a cross-browser, cross-platform plug-in for delivering the next generation of .NET based media experiences and rich interactive applications for the Web. Silverlight offers a flexible programming model that supports AJAX, VB, C#, Python, and Ruby, and integrates with existing Web applications. Silverlight supports fast, cost-effective delivery of high-quality video to all major browsers running on the Mac OS or Windows.

Read more

Components of the WSDL File

definitions: The root element of the WSDL file. This area contains namespace definitions that you use to avoid naming conflicts between multiple web services.

types: (not shown) Defines data types used by the service's messages.

message: Defines the data transferred by a web service operation, typically the name and data type of input parameters and return values.

port type: Defines one or more operations provided by the web service.

operation: Defines an operation that can be remotely invoked.

input: Specifies an input parameter to the operation using a previously defined message.

output: Specifies the return values from the operation using a previously defined message.

fault: (not shown) Optionally specifies an error message returned from the operation.

binding: Specifies the protocol used to access a web service including SOAP, HTTP GET and POST, and MIME.

service: Defines a group of related operations.

port: Defines an operation and its associated inputs and outputs.

Escape Characters in JavaScript!!!

Hello all,

I found the list of escape characters which you can use in java script for giving stylish message to end user.

Read more...

Event Bubbling

Event bubbling is the process of moving an event up the control hierarchy, from a control low in the hierarchy - such as a Button within the row of a DataGrid - and percolating it up to an ancestor control - such as the DataGrid.

Read more

Check that the SMTP server accepts email

Follow these steps to simulate what FogBugz does when it tries to send mail. If you see an error at any point, it will likely give you some clues as to what's wrong with the SMTP server.

From the computer where FogBugz is running, open a command prompt (choose Start, Run, type cmd, and click OK).
Type

telnet smtpserver 25

If you get a message that says something like Connect Failed, the SMTP server in question is not accepting any connections. This may be because:
the SMTP server is not running
the SMTP server is configured to reject email connections from the FogBugz machine
If all is well, you will see a message that starts with the number 220 followed by a greeting.
Type

HELO smtpserver

You should see a message starting with the number 250 followed by something glib like "pleased to meet you"
Using the email address configured as "Notification Return Address" in the FogBugz Site configuration screen, type

MAIL FROM:youremail@example.com

You should see a message starting with the number 250 followed by something like Sender ok.
Using the email address you want to send a notification to, type

RCPT TO:email@example.com

You should see a message starting with the number 250 followed by something like Recipient ok.

If you see a message that says something like "Relay Access Denied" -- this means that the SMTP server is configured to refuse any email that is not intended for its own domain. For example if you are sending mail to joe@example.com using an SMTP server at mycompany.com and you see a message about relaying denied, this SMTP server probably thinks you are a spammer. You will need to find an SMTP server that is configured to accept email from the FogBugz machine to its recipients.

Type
DATA

You should see a message starting with the number 354 followed by instructions to enter the email message..
Type
Test message
.

Note that the last line contains a period (dot) alone. This signals that you are done typing the message.
You should see a message starting with the number 250 followed by something like Message Accepted for Delivery.
Type
QUIT

Check that the email was received. If it was not received even though the message was accepted for delivery, there is something wrong with the SMTP mail server.

Jun 1, 2007

Cannot convert null to 'int' because it is a value type

Hello friends,

I found solution for the following error:

Cannot convert null to 'int' because it is a value type

when i wrote

int i = null

Now we can assign null values to such value types viz. int, datetime, float...

Check out Nullable Types

May 29, 2007

Calculate period of time with .NET

Hi all,

We all are facing problem in calculating difference between date.

I have one good delicious, have a look at Calculate period of time with .NET.

May 22, 2007

Global.asax problem in Webservice...

hello all,

I came accrosse one situation where i need to execute code on Application Start, but due to some problem webservice was not executing code written in Global.asax file.

After googling i got good link as soluction, The missing part was code file

Have a look at delicious Problem with Global.asax file in VS 2005.

May 19, 2007

ANTS Profiler - .NET code and memory profiler

ANTS Profiler identifies performance bottlenecks in applications written in any of the languages available on the .NET Framework. To profile your application, use your application as normal within ANTS Profiler. During the performance profiling, ANTS Profiler records the frequency and time it takes for each line of code to be executed, as you are using your application. Detailed results will then reveal the slowest lines of code and methods, allowing you to quickly identify performance bottlenecks and optimize your .NET application accordingly.

Have a look at delicios.

May 11, 2007

Implementing the Singleton Pattern in C#

Hi

I found good article on Singlelton Pattern, what is singleton, how to implement etc ....

Have a look at delicios.

May 10, 2007

HTTP Response Codes

Hi all,

In the web world we are getting lots of HTTP error, i have delicios which has all the response codes with its description.

May 5, 2007

A Complete URL Rewriting Solution for ASP.NET 2.0

Hi All,

I found one interesting article, which is simply best for URL Rewriting.

I have delicious on URL Rewriting

May 3, 2007

Avoid dynamic query at some extend [SQL 2k]


select * from [northwind].[dbo].[orders]
This will probably returns 830 rows [thats default],

Now what if I want top 10 rows or to 20 rows may be more, I will create dynamic query like...
declare @statement varchar(100)
declare @iTop int
set @iTop=3
set @statement ='select top ' + convert(varchar(2),@iTop) + ' * from [northwind].[dbo].[orders]'
EXEC (@statement)
We can do as follows which don't requrie creating dynamic query.

declare @iTop int
set @iTop=3
set rowcount @iTop
select * from [northwind].[dbo].[orders]
This will display top 3 records!!

Now set rowcount to 0 to get all the records

set rowcount 0

Apr 4, 2007

Exception Handling in SQL2k5

Hi

For handling exception just need to write 4 additional statements!


BEGIN TRY
print convert(int, 'hi')
END TRY
BEGIN CATCH
print @@ERROR
print 'ERROR'
END CATCH

OUTPUT:
245
ERROR

It's simple!!

Mar 20, 2007

Playing with location of window in javascript

I found some properties and method which is really usefull while working with window location

· Properties

window.location.hashthe part of the URL that follows the # symbol.
window.location.hostthe host name and port number
window.location.hostnamethe host name (without the port number).
window.location.hrefThe entire URL
window.location.pathnameThe path (relative to the host).
window.location.portThe port number of the URL
window.location.protocolThe protocol of the URL
window.location.searchthe part of the URL that that follows the ? symbol


· Methods
assign(url)Load the document at the provided URL.
reload(forceget)Reload the document from the current URL. forceget is a boolean, which, when it is true, causes the page to always be reloaded from the server. If it is false or not specified, the browser may reload the page from its cache.
replace(url)Replace the current document with the one at the provided URL. The difference from the assign() method is that after using replace() the current page will not be saved in session history, meaning the user won't be able to use the Back button to navigate to it.
toString()
Returns the string representation of the Location object's URL. See the JavaScript
reference for details.


I have delicious on JavaScript

Mar 2, 2007

Overload property in .NET

Hello Friends,

I have new information to .NET programmers.
We can create or rather I say we can overload the property in VB.NET and C#
But there is a very vast difference in both languages

· VB.NET

Private ReadOnly Property MA() As String
Get
...
End Get
End Property

Private ReadOnly Property MA(ByVal movAvg As String) As String
Get
...
End Get
End Property


Ohh this is working like function overloading! But still its property!

· C#

public string Author
{
set {_author = value;}
get {return _author;}
}

public AuthorEntity Author
{
set {_authorEntity = value;}
get {return _authorEntity;}
}

You will be attempting to overload a function which differs only by return type, and it won't compile. this is why properties can't be overloaded in the way you want - because they are converted to get functions which would only differ by return type.

You can see the difference in both language. And its working!!!

Feb 28, 2007

Operator Overloading in VB.NET

Hi,

We can overload the
I got good link having example how to overload the Operator in VB.Net.

Have a look at this delicious.

Formating output in C#

Hello,

I come across blog which is very useful to format our output using string.Format() in C#

http://blog.stevex.net/index.php/string-formatting-in-csharp/

I have delicious on C#

Feb 23, 2007

Personalise Your Site's Bookmark [Adding icon in addressbar]

Hello,

I had requirement in which I have to add icon in addressbar, its really simple.

You just have to create one icon file Favicon.ico

Now how to Create a "Favicon.ico" File?

· Create an image 16X16 pixels in size. Yes, it is really small and you can't really draw much in it. You should also restrict yourself to the standard Windows 16 colours, although I suspect that 256 colours will work fine.
· If you like, you can also create a 32X32 pixel icon, which will be scaled to size for the Favorites menu and the location bar. You can even put both 16X16 and 32X32 pixel icons into the same icon file. Windows will use the former for its menus and the latter when the user opens up a folder that is set to display large icons. It's probably not really necessary to do this if you can't be bothered.
· Save the image as an ICO file (named "favicon.ico", of course).
Upload it to your website. You don't need to upload one to every directory of your site if you don't want to waste space - simply put it in your root directory and IE will apparently locate it eventually. You can also upload it into your images directory, but you will need to modify your web pages if you do. See later in this article for more information

Helping the Browser Locate the favicon.ico file
If you have placed your favicon.ico file in a location other than the current web directory (relative to your web page) or the root directory, you have to help your visitors' browser locate the favicon file by specifying it with a tag like the following in the <head> section of your web page.

<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />

Feb 21, 2007

Some hints for developing High-Performance ASP.NET Applications

I observed the following points to be kept in mind while developing application in ASP.NET

· Disable session state when you are not using it.
· Use Page.IsPostBack to avoid performing unnecessary processing on a round trip
· Save server control view state only when necessary
· Do not rely on exceptions in your code [Avoid try, catch block]
· Use the common language runtime's garbage collector and automatic memory management appropriately [try to avoid having objects with Finalize methods] see Automatic Memory Management.
· Use the HttpServerUtility.Transfer method to redirect between pages in the same application
· Use early binding in Visual Basic .NET or JScript code [Include a Strict attribute in the @ Page directive or, for a user control, in the @ Control directive]
· Use SQL Server stored procedures for data access
· Use the SqlDataReader class for a fast forward-only data cursor [SqlDataReader class offers higher performance than the DataSet class]
· Choose the data viewing mechanism appropriate for your page or application [DataGrid Web server control can be a quick and easy way to display data, but it is frequently the most expensive in terms of performance.]
· Cache data and page output whenever possible
· Be sure to disable debug mode
· Enable authentication only for those applications that need it
· Consider disabling AutoEventWireup for your application
· Remove unused modules from the request-processing pipeline

I also have delicious on ASP.NET Performance and optimization

AutoEventWireUp is hitting the performance!!!

Yes its true,

Consider disabling AutoEventWireup for your application.

Setting the AutoEventWireup attribute to false in the Machine.config file means that the page will not match method names to events and hook them up (for example, Page_Load).

If page developers want to use these events, they will need to override the methods in the base class (for example, they will need to override Page.OnLoad for the page load event instead of using a Page_Load method).

If you disable AutoEventWireup, your pages will get a slight performance boost by leaving the event wiring to the page author instead of performing it automatically.

Problem after converting Vb.net to C#

Hello,

I was converting my vb project to C# using converter. This tool is really helpful to me for converting my vb application.

It converts successfully, but i notice some points that needs to be checked after done conversion

· Ensure that each page must have C# as language
· Container.DataItem("Field") must converted to DataBinder.Eval(Container.DataItem,"Field")
· Check for the inline code

Feb 18, 2007

Difference between properties and method [Microsoft Design]

In most cases, properties represent data, and methods perform actions. Properties are accessed like fields, which makes them easier to use. If a method takes no arguments and returns an object's state information, or accepts a single argument to set some part of an object's state, it is a good candidate for becoming a property.

Properties should behave as if they are fields; if the method cannot, it should not be changed to a property. Methods are preferable to properties in the following situations:
· The method performs a time-consuming operation. The method is perceivably slower than the time it takes to set or get a field's value.
· The method performs a conversion. Accessing a field does not return a converted version of the data it stores.
· The "Get" method has an observable side effect. Retrieving a field's value does not produce any side effects.
· The order of execution is important. Setting the value of a field does not rely on other operations having occurred.
· Calling the method twice in succession creates different results.
· The method is static but returns an object that can be changed by the caller. Retrieving a field's value does not allow the caller to change the data stored by the field.
· The method returns an array.

I also have delicious on Microsoft Design [Use properties where appropriate]

Feb 16, 2007

Static holder types should not have constructors [Microsoft.Design]

I created class which has all the static methods, look at the following code there is no compilation error



public class ServerController
{
public static ArrayList GetHttpServers() { ... }
public static ArrayList GetXmlRpcServer() { ... }
}


But as fas as performance concern this is wrong!! Why?

Warning : Remove the public constructors from 'ServerController'.

But i havnt declare any constructor!!

I can explain you, the default constructor is created automatically so how to avoid this message.

Two ways, 1) Make default constuctor as private or 2) Or make your class static.

Now look at class again



public static class ServerController
{
public static ArrayList GetHttpServers() { ... }
public static ArrayList GetXmlRpcServer() { ... }
}


Simple right?

I also have delicious on Microsoft Design

Feb 15, 2007

Pass arguments what requied [Microsoft.Design]

I come across one situation where I have to set visibility of panels, and I have to that code frequently so I created on function which accepts panels as argument…


public static void SetNoDataFound(Panel pnlToShow, Panel pnlToHide, Label txtToShowMessage, string strMessage)
{
pnlToShow.Visible = true;
pnlToHide.Visible = false;
txtToShowMessage.Text = string.Format(DefaultCulture, GetNoDataFoundMessage, strMessage);
}



Strange!! But it’s simply true. If you are using property of parent object then why should you pass child object?

So here is modified version of code, you can say optimized!!




public static void SetNoDataFound(Control pnlToShow, Control pnlToHide, Label txtToShowMessage, string strMessage)
{
pnlToShow.Visible = true;
pnlToHide.Visible = false;
txtToShowMessage.Text = string.Format(DefaultCulture, GetNoDataFoundMessage, strMessage);
}



You can see the change, instead of Panel I write Control which is parent of Panel.
This means that at the time of calling this function it’s just sent the reference of Control not Panel :)

Compare two objects!!!


Use IComparer Generic Interface.

This interface provides


public int Compare(object x, object y)

you overiddes this method and implement yours, so simple right?


Example:


public class MyComparer : IComparer
{
public MyComparer() { }

public int Compare(object x, object y)
{
return DateTime.Compare(((MyClass)x).EntryDate, ((MyClass)y).EntryDate);
}

}
A delicious related to this topic!

Feb 14, 2007

Find text in Stored procedure

Hi,

One interesting query I found which searches word in stored procedures and returns the name of procedure which contains that word
SELECT DISTINCT
o.name
FROM sysobjects o
INNER JOIN syscomments c ON (c.id = o.id)
WHERE
xtype = 'P' and category = 0 and c.text LIKE '%SearchWord%'
ORDER BY
o.name

Sqlserver Date and time functions

A delicious for sqlserver date and time functions

JavaScript Verifier (Verify your Javascript)

Website for Verifying your javascript

http://jslint.com/

It reports lots of small mistake which could be avoided and make javascript perfect...

This will help you to use your application in multiple browser

Feb 10, 2007

Trackback problems!!

Hi,

i had implemented incomming trackback handler.

following may be helpful in implementation.

http://scottwater.com/blog/archive/Trackbacks/
http://www.xaraya.com/documentation/rfcs/rfc0047.html