how to avoid form load again after loading the page in
in my case when i am selecting any item from dropdownlist then form is loading again & again & after selecting item second time it's giving me the selected value, so how can i get selected value at the first time??


Recommended Answers

All 12 Replies

Your page is being 'posted back'

Disable the auto post back property of the dropdown list.

enable the autopost back of the dropdown list and then in selected index changed event get the selected value.
when you click the dropdown it will show the items and after you click any item the selected index property is changed and you can select the value of selected item.
this will post back once on the selectedindexchange .

Check the Code behind file of the Aspx file to see if the Autowireup attribute is set to true. If it is true change it to false.
I propose this solution bearing in mind that you are using vs below 2005.

i am using vs 2008, 2.0 AutoEventWireup is false,i changed it to the true but doesn't work.. so how to avoid form load ?
in my case 1st time when i am selecting any item from dropdownlist it doesn't display any thing in that case page is loaded, when i am selecting again from that dropdownlist it's giving me required result . but i want to do it 1st time only,how to do it please help me....

May i asked how are you loading the dropdownlist and at what point? The code in the selectedindexchange can also be clue if you can provide.


If this behavior its because of some code that you have in the Page_Load method the you should try something like this

protected void Page_Load(object sender, EventArgs e)
        if (!Page.IsPostBack)
           //Your code here


i am filling that dropdownlist from the databse, i wrote some code in the selected_indexchanged event but 1st time when i select any item from dropdownlist, page load occurs & when again i am selecting any item from dropdownlist in that case also page load occurs, so without loading that page i want to do processing on selected item from that dropdownlist.
how to do it??


If what you want it's that the page don't 'blink' you should conssider using the UpdatePanel control.


Try to set the selected index of the dropdown to 0 after adding all items to the control and do the items addition in not post back condition like this...

if not (page.ispostback)
your code to add items in dropdownlist

i am sure this will solve your solution and dont forget to mark solved if problem is solved

i am using that code in page_load i.e
in page load i have a code as : If Not Page.IsPostBack Then Dropdownlist1.SelectedIndex=0, & i have a code related to the Dropdownlist in a function, but still it's not working, how to solve the problem??

can u post all u r code including drop downlist

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.