Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 ASP.NET
 Using scripts with Web Controls vs. HTML Controls

Author  Topic 

Billkamm
Posting Yak Master

124 Posts

Posted - 2006-01-20 : 08:54:36
When using <SELECT> I can use the onchange event to execute some javascript code at the top of my document.

However, it appears that when I use <asp:dropdownlist> and the OnSelectedIndexChanged event that I have to post back to the server to execute any code. Is it possible to have javascript code execute on the client side when my asp:dropdownlist is changed or do I have to use a <SELECT> statement to accomplish this?

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2006-01-20 : 09:15:04
You should be able to add any standard HTML attributes to server-side controls, just be sure that they are rendering to the HTML tag that you expect (i.e., be sure that asp:dropDownList renders as a SELECT, which I am pretty sure it does). Doing this allows you to write client-side script to capture events on the page the same as any other HTML page. Of course, remember that the client-side script cannot interact with server controls, except as rendered in the document object model, since they are in a different context.
Go to Top of Page

saglamtimur
Yak Posting Veteran

91 Posts

Posted - 2006-01-21 : 19:01:48
If you want to fire client side javascript function and disable postback of dropdownlist, set AutoPostBack property to false, then add this code in Page_Load
DropDownList1.Attributes.Add("onchange","jscriptfunctionnamehere();")
Go to Top of Page
   

- Advertisement -