I have a CascadingDropDown on an ASP.NET page.
Now, the prompt text is "Select State". (list of states).
However, on a different version of this page (ie querystring), i might want to set the selected index to "California" for example.
How can i do this?
The web service used by the ajax control (ie GetStates) gets invoked at the same time the jquery document.ready function is triggered (ie asynchronously).
So when i try and set the selected index in jquery, the items are not yet bound.
Is there a way to attach a handler to the ajax dropdown so that i can set the selected index once the webservice call has completed, and the items are bound?
So instead of trying to get tricky, i ended up replacing the CDDL with regular client-side dropdownlists and extending them with jQuery/AJAX.
Related
I have a Y/N dropdown list that I would like to update from the view (instead of updating it on the Edit page). For example, if I select "Yes" I will be redirected to the index page which will display "Yes". If I change it to "No" it will show "No". The result will be saved to the database. Basically, I want to call the edit method for the Y/N property on my index page.
What is the best way to go about this?
Here is one way to do it :
Wrap the dropdown list in a form that will POST to the server.
Not necessarily the Edit action... it could be some more specific UpdateYesNo action.
Listen for change events on the dropdown list.
Submit the form programmatically from within the change event.
Handle the request and redirect the client to the appropriate page.
Since this is a full POST request and not an $.ajax call we let AspNet Mvc handle the redirection.
So, basically my problem is that i have a series of tabs on my page, one of the tabs (not the default one) has two drop-down lists, the second drop-down list only populates after an item from the first drop-down list is selected, obviously without putting the autopostback = true value in my drop-down list, they wont automatically populate however adding autopostback = true causes the page to reload and changes tabs back to the primary default tab. Is there any way around this that people know as i don't really want the users having to change back to the correct tab 4 times to fill in a form. Thanks
I think your dropdown is asp:DropDown (server side). I recomend you to use html element and do your staff at front end with jquery,ajax etc. But in your case if you want to update part of the page without using front end tools (jquery-ajax), You should use asp:UpdatePanel for it. Search for it, it is not so complex. Good luck.
Introduction to the UpdatePanel Control
How do I use updatePanel in asp.net without refreshing all page
How do you bind each item in a dropdownlist to a different JQuery function?
For example I have a dropdown with different report names, I want each time you select the drop down to trigger a new report to display.
I accomplished this before with just straight text links with Report 1 which called $("#btnReport1").bind("click", function () {...}
I want to call the same function above from each of the different report items in the dropdownlist. There will be 5 or so I'll need to call. Is there a way to embed a link in each item? Do I use "change" somehow over "click" ?
I'm using Razor and MVC.Net so I could do something like #Html.DropdownList(...) with a SelectList object and put code in the controller file if need be. But I prefer to handle this on the HTML though.
sounds like you're trying to bind to a select dropdown. the best way to accomplish this is the onChange() handler (see the docs for details).
from there, you would simply determine which option had been selected based on the current value (probably obtained via the .val() method) and perform an action based on that value, using an series of if statements or another method.
Just call a single function on the click event and have it look at the value and decide what specific report to load from there.
I have a drop down list which is being populated with data from a database using a datasource in visual studio 2010. All the values are unique and I have set up an event to carry out an action when a new value is selected. When I select a new value in the drop down list the new value is selected but the event does not fire. I put a break point in the code to see if it was being executed which was not being hit.
I read about setting the drop down lists AutoPostBack to true but all this seems to do is refresh the page and set the list back to its original selected state (possible why the event is not firing?).
I also read something about enabling the ViewState as this could cause it to not fire, I tried putting EnableViewState = "true" at the top of the View to no avail. The EnableViewState property is also set to true on the drop down list.
I would be grateful if anyone has any insight into a solution?
Thanks
With Asp.Net MVC you do not have events and postback like Asp.Net.
You should use a form tag to handle the values of your drop down, because it's a classic HTML page. If you want to handle in a async way, use javascript connected to the onchange of your dropdown
I usually find this is caused by databinding. If code in Page_Load binds the dropdownlist without checking Page.IsPostBack (Or somewhere else in the pipeline before control events are handled) that will suppress the SelectedIndexChanged event.
Another possibility is that you haven't got OnSelectedIndexChanged="DropDownListId_SelectedIndexChanged" in the decalrative markup for the control, or in the #Page directive you don't have AutoEventWireup=true.
Can you post your code?
Just seen tag and #iridio's post. Is this really MVC ? I would'nt expect to see System.Web.UI.WebControls used in an MVC app, but I am no MVC expert.
I am creating online booking page.
I got some example page you can see in this link
http://www.parkercorporate.co.uk/webbookercc/OneForm.asp
I need the same behaviour in my site whenever user selects value in pickup dropdown list in the right side I need to change the text values or view.
To do this behaviour how should I write code in ASP.NET and c#.
Thanks
Ranam
First, use an UpdatePanel so you don't see any visual postback.
Second, set the AutoPostBack property on your DropDownList to True.
Third, handle the DropDownList's SelectedIndexChanged event. This will now fire after every change in the DropDownList, because you enabled AutoPostBack.
In the event handler, you can now change the ActiveViewIndex of the MultiView, or show/hide controls, change textboxes, etc.
First, create different blocks (i.e divs) and give ID's to them.
Then, for each value in the dropbox, fill the divs w.r.t it.
Assign "OnChange" event to the dropdown, and in the handler, set visible or invisible to corresponding block.
On the other hand, If you want to do this on client side, I strongly suggest you to use JQuery, to prevent a lot of requests going to server.
Check this out with JQuery:
make visible div on dropdown select in jquery
If you won't fetch values from database, there is nothing complex about this page. Because it just writes hospital if you choose hospital etc. and changes control's visible state.
Even if you think you need db queries when dropdown's selected change event, actually at this page there is no need. Just store db values in hidden controls (like Hospital- for Hospital) and when dropdown selection changes, write hidden's value completely in javascript