开发者

The best way of writing code to enable or disable some controls

Hi all i don't know whether it is correct or not to ask this type of questions but i would like to know the best and secure way of writing code. Actually i had some list of check boxes on which each selection particular DIV will get loaded. I would like to achieve this using 2 ways

   1. Writing Java scripts to enable or disable
   2. In code we can enable or disable particular DIV

i would like to know which is the better way to write

If i use Java script means if i had n no of check boxes then i would like to write n no of functions.

If i code means each end every time 开发者_JS百科post back occurs and load on page

So what is the better way to choose


Both the approaches have their own advantages and disadvantages.

Using JS you will definitely get better user experience & better performance. But it’s not reliable as someone might disable JS in the browser and you also need to think of browser compatibility.

When you use server side code to do this in that case you need to posback the page to achieve this which will be time consuming and user might get irritated, but this approach is much reliable, here only required HTML will be rendered at the client side. I will suggest you to use jQuery for doing this as jQuery is supported by all the browsers and check if the JS is disables in that case use the normal postback technique.

Remember, you need to write some generic functions which takes control id and toggle the control as required, this way you don't need to write redundant code.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜