Click here to Skip to main content
6,306,412 members and growing! (20,188 online)
Email Password   helpLost your password?
Web Development » ASP.NET » General     Intermediate

A Client Script Helper Utility Class

By Mohammad Ashraful Alam

The "ClientScriptHelper" utility class will help you by not requiring you to remember the client side codes.
Windows, .NET, ASP.NET, Visual Studio, Dev
Posted:19 Mar 2006
Views:22,010
Bookmarked:24 times
Unedited contribution
Announcements
Loading...
 
Search    
Advanced Search
printPrint   Broken Article?Report       add Share
  Discuss Discuss   Recommend Article Email
34 votes for this article.
Popularity: 5.50 Rating: 3.59 out of 5
4 votes, 11.8%
1
4 votes, 11.8%
2
3 votes, 8.8%
3

4
23 votes, 67.6%
5

Sample Image - clnt_Side_src.png

Introduction

Using the "Add" method of "Attributes" property of ASP.NET web controls you ca add client side functionalities (like showing message, print dialog, close browser, browser back, pop-up window etc) to your code. However, invoking the client side behaviors to the web controls, you have to remember the corresponding client script codes as well as each time you want to use that by adding the corresponding attribute. The "ClientScriptHelper" utility class will help you by not requiring you to remember the client side codes in this case.

 

Using the class

 

As the "Add" method of "Attributes" property of ASP.NET web controls requires to be invoked in the "Page Load" event of the ASP.NET, you need to call the helper static methods, in the corresponding event handler.

 

protected System.Web.UI.WebControls.LinkButton lbtPrint;
protected System.Web.UI.WebControls.LinkButton lbtClose;
protected System.Web.UI.WebControls.LinkButton lbtShowPopup;
protected System.Web.UI.WebControls.LinkButton lbtShowMessage;
 
private void Page_Load(object sender, System.EventArgs e)
{
    if ( !IsPostBack)
    {
    Ashraf.ClientScriptHelper.AddPrint(lbtPrint);
    Ashraf.ClientScriptHelper.AddCloseWindow(lbtClose);
    Ashraf.ClientScriptHelper.AddOpenPopupWindow(lbtShowPopup, "http://www.codeproject.com/">http://www.codeproject.com/");

    Ashraf.ClientScriptHelper.AddMessage(lbtShowMessage, "Hello World");
    }
}

 

 

In the provided sample page we have four ASP.NET LinkButton control, for each of them we have assigned different functionalities. Since, to add client side functionalities to the web controls only once is enough, we call the methods in the "!IsPostBack" code block.

 

The code below adds the 'Show Message box' functionality to a web control:

 

Ashraf.ClientScriptHelper.AddMessage(lbtShowMessage, "Hello World"); 

 

The code below adds the 'Pop-up' functionality to a web control:

 

Ashraf.ClientScriptHelper.AddOpenPopupWindow(lbtShowPopup, "http://www.codeproject.com/">http://www.codeproject.com/");

 

The code below adds the 'Print Dialog' functionality to a web control:

 

Ashraf.ClientScriptHelper.AddPrint(lbtPrint);

 

The code below adds the 'Browser Close' functionality to a web control:

 

Ashraf.ClientScriptHelper.AddCloseWindow(lbtClose);

 

Conclusion:

 

Any advice or correction for this class will be highly appreciated.

 

 

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Mohammad Ashraful Alam


Member
Mohammad Ashraful Alam is a Software Engineer, who is dedicated to Microsoft .NET based development. This Bangladeshi national is involved with project management and development of several US based software projects from his country. Already he has managed and developed 15 software projects, which are being used by several users of different countries, such as USA, Canada, Australia, and Bangladesh. While developing and managing a team, he contains and maintains a set of well defined engineering practices developed by him and other online developer community. Beside software development, he has also written several technical articles and research papers published by IEEE Computer Society and many other worlds recognized publishers.

Before becoming engaged with software development, he was involved with Bengali literature and several Bengali news papers as freelance journalist and published around 150 articles, essays and short stories.

Due to his willingness to give effort to improve and share better software development practices, Ashraf has awarded as “Most Valuable Professional” (MVP) in ASP.NET category by Microsoft for multiple times, since 2007.

When not engaged with technical stuffs, he likes to pass time with his friends, and family members, listens music or watches TV.

Check his blog: here.

Shoot Ashraf in mail, "joy_csharp AT hotmail.com" if you have any interest to contact with him.
Occupation: Chief Technology Officer
Location: Bangladesh Bangladesh

Other popular ASP.NET articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 3 of 3 (Total in Forum: 3) (Refresh)FirstPrevNext
Generalthere's an unwanted postback. Pinmemberwingi11:28 21 Mar '06  
GeneralBuggy PinmemberDeKale8:42 19 Mar '06  
GeneralRe: Buggy Pinmemberjoycsc8:46 19 Mar '06  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 19 Mar 2006
Editor:
Copyright 2006 by Mohammad Ashraful Alam
Everything else Copyright © CodeProject, 1999-2009
Web17 | Advertise on the Code Project