468,545 Members | 1,741 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,545 developers. It's quick & easy.

populate the Dropdown list by client side using javascript

Hi this is venkat,
i have a drop downlist for country, i composed a code in javascript for that and its working in HTML page but i dont know how to call the same javascript function in asp.net(C#) dropdownlist. please advice me and send me code for how to call the function..
Mar 19 '08 #1
4 2634
Be specific in the question.

You can call the javascript method on any event which you can do by writing it either in the aspx page or in the code with (control.attributes.add("[Event]","[javascript code or function call]"))
Mar 19 '08 #2
Frinavale
9,735 Expert Mod 8TB
Hi this is venkat,
i have a drop downlist for country, i composed a code in javascript for that and its working in HTML page but i dont know how to call the same javascript function in asp.net(C#) dropdownlist. please advice me and send me code for how to call the function..
Hi Venkat :)

JavaScript works in the browser (client side).
Your C# code works on the web server (server side).
You cannot call JavaScript functions from your C# code.

What you can do is set each of your DropDownList Items to have an "onclick" event:

Expand|Select|Wrap|Line Numbers
  1. foreach(ListItem i in MyCountryDropDownList.Items)
  2. {    i.Attributes.Add("onclick","theJavaScriptFunction();");}
  3.  
This will cause the JavaScript function to be called when ever the DropDownList item has be clicked on.

If you need your C# code to generate your country list on the server, then you must implement this in C#. You cannot call your JavaScript function from the server.
-Frinny
Mar 19 '08 #3
Hi Thanks for quick reply
i need like below link- just click this url and see there is country option- http://www.24x7a2z.com/iff/ver2/feedback.html. after selecting the corresponding country, then i will store that selected country to DB? will it possible to do that? please let me know how it possible?...
Mar 20 '08 #4
Frinavale
9,735 Expert Mod 8TB
Hi Thanks for quick reply
i need like below link- just click this url and see there is country option- http://www.24x7a2z.com/iff/ver2/feedback.html. after selecting the corresponding country, then i will store that selected country to DB? will it possible to do that? please let me know how it possible?...
You could create a database with a table for your countries...then you can populate your DropDownList with countries retrieved from the database.

Normally when you have a form like that you are saving the person's information in some way. Saving it into a database is a good idea.

-Frinny
Mar 20 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

32 posts views Thread by Continental Translations | last post: by
1 post views Thread by Ed Chiu | last post: by
5 posts views Thread by John A Grandy | last post: by
2 posts views Thread by Nick | last post: by
11 posts views Thread by eureka | last post: by
1 post views Thread by UniDue | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.