开发者

Server or CLIENT side Custom ASP.Net Controls?

I am an undergraduate student , and working on my Final Year project these days. I ha开发者_开发知识库ve some queries related to Custom Controls as follows: I am designing a text box field which will have three or more functions as follows :

  • Either it will allow numeric characters only
  • Or it will allow an email address to be taken as input
  • Or it will be a file Upload text box

I am using jQuery to validate this text box .for eg. for checking whether the user has entered numeric characters only or not!!

My Question is

  • What is the better approach to build such custom controls ? Either make it pure client side or pure Server side or both?
  • Also , I need to include AJAX functionality in file uploader. If the client browser doesnot support JavaScripting for some reason then how we can avoid this constraint ? Thank you very much for your time ! Kindly help me.


  1. First of all you have to decide if you need both client-side and server-side functionality for your control. It will depend on your needs. If you are writing it as part of a large application, I would suggest going for both, because it's much easier to manage. If you decide that you do want both, ASP.NET includes exact functionality that you are looking for. It's called Extender controls. They will allow you to create a custom server-side control and extend that control to include some client-side functionality. You can get more information about Extenders here.

  2. Graceful failing AJAX controls are rare, majority of the developers that create AJAX controls assume that all clients will have JavaScript turned on. However, they are not that hard to do. Actually they are very easy to do, if you are using ASP.NET AJAX Update Panel. Update Panel itself will automatically switch to full post-back if JavaScripts are disabled. If you are using custom implementation of AJAX, or jQuery (as you mentioned above), you have to follow a few simple rules. First of all, avoid binding events from inside scripts, use onclick, onmouseover, etc. This way, if a link has onclick event, and a valid href tag, if JavaScript are on, you will process onclick event handler, but if they are off, you will just follow href attribute value. For the uploader, you can put your uploader inside the FORM element, and add onsubmit event to it. If JS is on, you will process onsubmit, and do an AJAX call to save the file, if JS is off, you will do a full page post-back and save the file from the server-side.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜