2

I have 40 asp.net dropdownlists in my webpage. When i bind the controls in serverside using DataBind() it is taking 12 seconds, during which the page is blank. Without the databind, the page loads in 1 second.

So i decided to do the binding at client side. When i googled, i got this link. But the problem i am facing is, when i use PopulateControl() in javascript, i will get only the SelectedIndex during the postback.

The asp.net dropdown has the properties like SelectedIndex, SelectedValue, SelectedText. These properties are used a lot in the code-behind and changing the logic based on selected index would be very tough for me.

Is there a way where i can bind the control with javascript and get all those properties during postback.

Thanks in advance.

1 Answer 1

2

As the items in the drop downs were not there on page load they will not be accessible in the normal ASP.net way. Use the request object to get the selected values:

string selVal = request.Form["dropDownName"]; //C# code

Be careful if you are using MasterPages or other naming containers as the name passed in the Request object may be mangled.

You could also use a plain HTML select control here.

Sign up to request clarification or add additional context in comments.

4 Comments

The items are present in the aspx page. so i believe it should be available in the page_load. Only the data bound to those items are done in client side(Ajax). Though, i am wondering why the javascript-bound values are not available in code-behind(server-side) during postback.
Poor choice of words on my part. I was referring to the items (options) in the drop down lists themselves. On a side note do all the lists contain the same items or are they different? When you originally had page load times of ~40 sec were there multiple database calls or just one?
Oh. Okay. All those drop downs have different values. When i load the page with all DataBind() commented out, its loading in 1 sec. The controls will be empty now. So i rewrote the binding JS using ajax calls. The DB call is a single call and fetches all the 40 tables. It executes in 2 sec and the results are cached after 1st hit. So now i need to find a way that the <option>s added by JS should be visible in CodeBehind(assessing through the parent Dropdown id)
The only thing that comes to mind is to use an update panels to update the dropdowns as javascript alone will not update server side. How many items in the drop downs? THe issue could be page size. Have a look with a tool like firebug for firefox. It can show you wait times and page sizes. You could drastically reduce page size with your server side bound drop downs by disabling view states on the drop downs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.