How can I create a dynamic drop down list without using AutoPostBack. I ask because I just want to change the value of what the second drop down list displays and then the user clicks a button and it submits. But If I use AutoPostBack then it postbacks to page and runs code that shouldn't be run until that final box has been selected. (I use Postback in the other part of my program so using !IsPostBack isnt a option.) I looked at Javascript but ASP generates all of its controls names at runtime. What can I do? I have looked at the Ajax CascadingDropDown control but my problem with that is it contained in a XML file or a Database, I need this to be contained inside my Page. Any Ideas?
You can use the CascadingDropDown control from the AJAX Control Toolkit
Maybe this example will help? It's part of the ASP.NET AJAX Control Toolkit available here.
You can use AJAX to get the values for the second drop down list, based on the selected value of the first. Add a onchange event handler on the client-side to the first drop down list that makes the AJAX call and fills the second on success.
Related
I am looking for a textbox in C# which should work like dropdown search values when I type anything in the textbox. Those values will come from calling a method.. and I Should be able to select any of the values.
Do i need to use the asp dropdownlist or is there any other sample code available which could help me.
You should look into jQuery autocomplete feature.
http://jqueryui.com/autocomplete/
The ajax control toolkit provides Autocomplete extender to do just that. The control calls a method, which you specify, asynchronously and get all the values to be shown as an option. I would imagine these values would be retrieved when the page loads and will not be session specific so can be stored in a cache for faster retrieval.
http://www.asp.net/AjaxLibrary/AjaxControlToolkitSampleSite/AutoComplete/AutoComplete.aspx
I have 7 dropdown lists within my page , following a post back from dropdown list 1 I want this to still be highlighted when the page reloads so that I have the ability to tab to the next dropdown list
I have tried smart navigation but this did not work. I'm using framework 3
Any guidance would be appreciated
Thanks
You can use the focus() method
For example in code-behind:
DropDownList1.Focus();
This will give focus to DropDownList1
Alternatively you can use
Page.SetFocus("IdOfControl");
You will need to store the ID of the control in either a session or querystring so you can access it after postback so you know which control to give focus to.
First off, I have managed to create a web application where my dynamically created user controls are recreated and repopulated with the correct information upon postback. I am not sure what my problem is, but i hope that you will be able to help me figure it out based on my situation:
On my page i enter the number of controls to be created into a hardcoded textbox (its on the aspx page) and click the okay butten. This in turn, creates the specified number of user controls dynamically using c# in the background.
So far the desired number of dynamic controls are in a table on the page.
Next...
I have 1 textbox and 4 dropboxes on each dynamic user control. When i type a company name into the textbox field and press enter or click away (on text changed event) it autoposts back and the textbox retains the company name that i have typed in.
Based on this string the dropboxes are populated from the database. Now when i select the desired items from the dropboxes and click on the save button (located outside of the dynamic controls, on the page) it does an insert to the database, but it turns out that upon this postback the indexes from the dropboxes have been reset and the wrong values get inserted.
The following pictures show firstly, how it should be and then how it is.
Basically the company name remains in the textbox of the dynamic control, but the information i choose from the dropbox resets to the first index.
It's hard to tell what happend without code, but this is a common mistake:
If you fill/create the dropdownlist controls in the page load event and you post back, the code will refill/recreate the controls. That's why you have to use something like If(!IsPostBack) in your page load event. Otherwise it will execute that code everytime you do a postback and actually just want to execute the code in your event handler for that button.
If you're dynamically creating the controls, make sure to do that in the Page_Init event. Dynamic controls have to be recreated on every postback. Their state is restored after the Page_Init (if it is a postback), so make sure to only set their values in Page_Load if you want to overwrite them.
I've three images. I use javascript to mark which one is selected. After user clicks on one I change its class to active. its <li><a>. Now when I wasn't using updatepanel after form post I could see from code behind which element is active and it was correct. After adding updatePanel which contains entire form after postback which should refresh content of updatePanel value is wrong and active is always set to default first <a>. Whats more in this updatePanel there is UploadFile control which doesn't work well because it always has HasFile value to false even though I choose file.
Thanks You for any hints
Your form must be a full postback. You have to add a Trigger for the Full postback, if your FileUpload control is in the update panel.
Alternatively if you want to upload Asynchronously , you could try AJAX AsyncFileUpload control
http://asp.net-informations.com/ajax/ajax-AsyncFileUpload.htm
This is a well known problem, please take a look into the following article:
http://geekswithblogs.net/ranganh/archive/2008/04/01/file-upload-in-updatepanel-asp.net-ajax.aspx
I have a page index.aspx this page has two Web user Controls, list.ascx and display.acsx basically list.ascx shows all the lists that are available on that SharePoint site into a dropdown box. The second web user control, displays a list of all the files in the list selected. But there's where I run into the problem my question is how do I transfer the value of the dropdown box from the first web user control into the second one.
thanks
Given that you are using custom web controls, it's a bad idea I find, to intrinsically link two different controls together as dependents. Instead:
Define an event on the first control that is raised appropriately with event arguments containing the data.
Have the encompassing index.aspx page have a handler for this event.
Within this handler, set an appropriate property on the second control, passing the data from the event argument.
This is much cleaner, achieves what you want and de-couples the two controls from one another.
Your list.ascx needs to postback the ListId to the server when the value is changed
<select onchange="PostBackWithListId();" >
<option value="SomeListId">
</select>
jQuery could help here, or you could do it server side with OnSelectedIndexChanged and AutoPostBack.
Then your display.acsx, just needs to read the ListId from the request.
If you just want to pass the data once brutally, no strings attached:
make a class with a static member of the type of data you want to pass.
set the value in one ascx file and read in the second ascx file..