SelectedIndexChanged on dropdown in user control and event sequence...

carled
carled used Ask the Experts™
on
Hi there. I have a page that loads a few fields based on a current record on a database being selected. It does this in "page_load". Works fine.

Now I also have a user control on this page. In this user control, the user can select a different database record. I have got a custom event that I fire on the selectedindexchanged event and this successfully filters back to the main page.  The trouble is that the "page_load" event on the parent page fires BEFORE the "selectedindexchanged" event on the control!

So I need to pick the value that has been changed in the dropdown and use that in the "page_load" of the parent page... how do I do this please?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2013

Commented:
move you code in Page_Load into a  function and call that same method in when selectedIndeChanged e.g:
Page_Load(...)
{  somecode();
}
ddl_selectedIndexChanged(...)
{  somecode();
}
Or my be you can post your code in page_load to understand what exactly you need.

Author

Commented:
oh... I didn't realise I could call functions in the main page... let me just try that, hang on...

Author

Commented:
Hmm. I can't call the page function from the user control... says it doesn't exist, even though it's a public function...?
Exploring SharePoint 2016

Explore SharePoint 2016, the web-based, collaborative platform that integrates with Microsoft Office to provide intranets, secure document management, and collaboration so you can develop your online and offline capabilities.

Top Expert 2013

Commented:
oh my bad...i forgot your ddl is in usercontrol...So you are handling selectedIndexChanged from UC...
Then in that case expose and event from UC, raise that event from SelectedIndexChanged and handle it on the page. And in this handler you call SomeFunction() as before.
Something along these lines:
http://www.codeproject.com/Articles/51671/How-To-Expose-events-from-UserControl.aspx

Author

Commented:
Ah - I already do this, as stated in my OP. Also as stated in my OP, " The trouble is that the "page_load" event on the parent page fires BEFORE the "selectedindexchanged" event on the control! "

So I have my eventhandler in the main page:

AddHandler commonPageTop.version_changed, AddressOf Me.versionChanged
("commonPageTop" is my usercontrol)

In "selectedindexchange" I do:
        Dim ev As db_OutputValues = New db_OutputValues
        ev.versionID = ddl_Version.SelectedValue
        RaiseEvent version_Changed(Me, ev)

And, as I say, the "loadDetails" function is in "page_load" in the main page, this gets fired first, then the "selectedindexchange" event in the usercontrol, then the "versionchanged" handler in the main page. If I call "loadDetails" again at that point, I'll simply be loading the old values, then the new values straight after!

Author

Commented:
So... there not being a huge avalanche of interest in this, I decided to work around it by altering the parent page logic to load the datalist at a later stage and also check for page postback.  So the control raises the event, the parent page reloads, the event bubbles up and is captured and I reload the datalist. It's not ideal but it sorta works.
Top Expert 2013
Commented:
but you should be putting your page_Load loadDetails inside !IsPostBack like:
if(!Page.IsPostBack)
{ loadDetails(); //this will be called only on first time page request.
}
Upon subsequent request loadDetails() won't be called. Whenever you want to refresh the grid you simply call loadDetails.
Hope I am understanding your question right.
Top Expert 2013

Commented:
oh...I left the window open for long and my last post was reply to your #26450246.
So did you get it to work?

Author

Commented:
Yeah, it's sort of like that now. There are a couple of other things going on with the page that complicate things slightly, but it's pretty much like that now, thanks. I'll give you the points to wrap it up, as there's no other way of doing this without too much piddling about with delegate stuff ;-)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial