Monday, November 17, 2008

Javascript and

1) Access controls via Javascript:

-Javascript in .aspx page


-Javascript in .js file

First, you have to get the id of the control after the page is rendered (IE/FireFox->View->Page Source->Find the the control id)


2) Add Javascript function to controls:

NameOfControl.Attributes.Add("eventname","javascriptMethod") [vb]

NameOfControl.Attributes.Add("eventname","javascriptMethod") [C#]

Example: Validate empty value in a textbox.

-In aspx page add javascript function as following

<script type="javascript">
function IsEmpty()
if (document.getElementById('<%=textbox1.ClientID%>').value == "")
alert("Textbox is empty");

-In code behind, Add Following code on page_load



Validators on update panel not working properly

The problem is occurred seriously on window 2003. Error messages of validators is not displayed properly.

-Simulate the problems:

1. Create a sample ajax application.
2. Drag a textbox, a requirefieldvalidator and a button to an update panel.
3. Deploy it to web server running window 2003.
4. Leave the value in the textbox empty, then click submit button. It work fine in this stage.
5 Enter some text and click submit. At this time, server is doing asynchronous post back to the server. Finally try to leave the value empty again and click submit. You will not see the error message of validator controls.

- Solution:
1. There is a work around to solve this problem by setting EnableClientScript = False of every validator controls under update panel. This will disable client validatation, so instead we need to do validation on server.

{ //do actioin

2. Another solution from Matt Gibbs's blog:

It works fine most of the case,but it has a problem when setting "DisplayMode" of validation controls to "Dynamic". Validation is not fired unless the page submit two times.

Wednesday, November 5, 2008

65 Excellent jQuery Resources (tutorials,cheat sheets,ebooks,demos,plugins…)