DropDownList after reset button c# - c#

I have a c# dropdownlist inside a form. My goal is to hit a reset button and set the entire page back to the way it was when I first loaded the page. My textboxes are clear and everything is where it should be except my dropdownlist. It displays the last selected dropdownlist Item selected. I would like it to go back to the initial selection when I reload the page. How would I do this?
DropDownList1.ClearSelection();
or
DropDownList.Clear();
Doesn't work

DropDownList1.SelectedIndex= -1

Related

Asp.net Textbox.Autopostback causes another issue

I have dropdown and texboxes and one button on the form. I'm using 'autopostback=true' for all the form elements. When you fill the form you need to push 'send' button. But because of texbox.autopostback, you need to push 2 time to send form.
If you select dropdown lastly, then there is no problem. But if you're filling textboxes than you need to click 2 time to send form.
Is there any solution for it? I must use textboxes.autopostback='true' but need some solution.
Thanks,
UPDATE:
All controls stays in updatepanel element.
Set a hidden field value to "1" when textbox posts back and its value is valid, else set the hidden field value to "0"
On client-side, in pageLoad event, automatically click the button if the hidden field value is "1". So, to the user button is only clicked once and your auto submitting the form when text post back returns.
Both the above points need to be done in your code-behind.
The result of of this logic will enforce a consistent workflow, where the button can be clicked only once to submit the page.

Disable Gridview position change on navigateback

How to disable the scrolling on my gridView? When i click the back button after modifing my selected item.
as example u can create a default grid app
if you created a app based on this template and now select the a item in the last list and then click the back button it will scroll to the beginning. But it should stay over the last list.
When you goBack() a new instance of the first Page is created, that's what causes the lost of your scrolling, to fix that make sure that the first Page is cached so you will navigate back to the same instance using NavigationCacheMode
NavigationCacheMode="Enabled"

AutoPostBack ONCE on pageload

I have a listview with a dropdown, with autopostback enabled.
The user can select yes - which postsback and brings up loads more dropdowns, no - which brings up a textbox, and blank - which does nothing.
As the original dropdownbox is databound it displays one of those values but at the moment always acts as if it was blank ie no other controls showing..
Can I make the page do ONE autopostback as soon as it's loaded without any user input to display the correct controls if it's a yes or no as opposed to blank?
try calling dropdownbox_selectedindexchanged(null,null) after binding in page load. it is just calling selectedindexchanged event programmatically. as far as i know you want to load controls based on dropdown selection when page first load and user haven't changed dropdown value. so this code will call it from code behind.

choose a dynamic item in a dropdown without losing choice upon submit

Every time I click an ASP button on my page to select an item in my dropdown list, it is only choosing the first item in the list. It is as if every time I click a button the page refreshes and all variables reset. How do you choose an item from a dropdown when using dynamic data from a database?
This sounds indicative of populating the DropDownList in Page_Load. Is that the case? (I'm assuming you're using WebForms.) If you're populating the control in Page_Load then you'll want to wrap it in a conditional:
if (!IsPostBack)
{
// populate your controls from data
}
Otherwise, they'll get re-populated with each postback. When you click a button or perform some other action on the page which initiates a postback, Page_Load is called before the event handler. So in effect, this is happening:
User navigates to the page
Page_Load clears and re-populates the DropDownList
User chooses an item in the DropDownList
User clicks a button
Page_Load clears and re-populates the DropDownList
Button handler gets the current selection from the DropDownList, which is the default.
What do you mean by "click ASP button"?
If you are talking about the downarrow to open the dropdown list, then you need to set AutoPostback options to false if you don't want that opening the dropdown list triggers postback (that is on the other side required if you have any events related to the opening of your list).

using autopostback on dropdownlist that also has submit button

Have a dropdown list with autopostback set to 'yes' have another dropdown list box that will be populated based on the selection of the first dropdown. It works fine until I put a submit botton on the form. When I do it appears to not do the auto postback until the submit button is pushed. Can you have a submit button on a form that has a dropdown with autopostback active. thanks...
Sure you can.
Are you handling the autopostback event of the first dropdown in the code-behind file to populate the second dropdown? If so, your postback event should be firing when you change your selection in the first dropdown. Put a breakpoint in your code to assure that your event code is being called.
Sure you can. Are you seeing it not load the second dropdown? If so, check where you're handling that, as it may be in the wrong spot (if you're doing it with code) or you might have it wrapped in a !postback without thinking about it. Post more code and explanation for more help.

Categories

Resources