User control reloads page data when webcontrol changes

  • Thread starter Thread starter Matt Jensen
  • Start date Start date
M

Matt Jensen

Howdy all
Been searching and can't find a good answer to my problem.

I've got a usercontrol 'banner' at the top of my page, and when the
selection in the dropdown list changes I want the "host" webform/page to be
reload so the data on it (in repeaters) is reloaded using a new value from
the dropdownlist (and which btw is also stored in a session variable for
later use).

I'm not sure the best way to do this.
I could call a public method in the page class and try and repopulate this
but I'm not sure that with the .NET page
creation/initiation/render/whatever-the-correct-term-is order that this will
work, plus I can't get it to work anyhow (maybe I need to call the
InitializeComponent method generated by VS) but I don't really know what I'm
doing re this.

I've tried redirect the "host" page to itself but then I'm having problems
getting the dropdownlist to show the (just) selected value.

I was hoping there was a simple way to call the "host" page_load event from
the user control as this would make it much easier, but I'm not sure this
makes sense the in the .NET page load/creation order anyway. I read
something about delegates but I didn't really understand it and couldn't see
how to apply it to my case.

Any help would be greatly appreciated.
Cheers
Matt
 
Matt,
Problem of urs will be solved by checking for IsPostBack and do logic
for binding data to ur repeater control.
 
Hmm, I think my problem is related to the order of a dropdownlist
selectindexchanged event firing in relation to the page ispostback event.
Which fires first?
Cheers
Matt
 
Matt,
What I've used a lot in the past

1. Ensure that your DropDownList control has "AutoPostBack = true"
set.
2. Create a handler for the SelectedIndexChanged event from the
DropDownList.
3. In the handler add code that looks something like this

private void DropDownList1_SelectedIndexChanged(object sender,
System.EventArgs e)
{
// Get the selected value from the DDL
string selectedValue = DropDownList1.SelectedValue;

// Call a function to update the repeaters with the
// the new value from the DDL control
UpdateRepeaters(selectedValue);
}

In this manner, you can use the postback event to udpate the repeaters
on your page.

Hope this helps.

-tomas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top