Passing data to a usercontrol before rendering?

T

Tarun Mistry

Hi all, is it possible to update a usercontrol before it is rendered?

In my scenario I have a Page with a usercontrol on it. When a button is
clicked on the Page, I want to update the usercontrol, more specifically
making a placeholder become visible. However it wont work. Im confused. I
catch the button click even on the page and within this i run a method on my
usercontrol, however it doesnt seem to work. Few code lines given below.

Please help! Thank you!

In my PageI have something like this:

private void ButtonPatientSearch_Click(object sender, System.EventArgs e)
{
// construct dynamic search results
MyUserControl.ShowResults(ArrayListofObjects);
}

and in the user conrtol I have the method to catch this request

public void ShowResults(ArrayList ArrayListofObjects)
{
MyPlaceHolder.Visible = true;
Repeater1.DataSource = ArrayListofObjects;
Repeater1.DataBind();
}
 
G

Guest

Hi Tarun,

You should get the usercontrol reference first:

MyUserControl myUserControlObj =
(MyUserControl)Page.FindControl(MyUserControl_ID);
myUserControlObj.ShowResults(ArrayListofObjects);


HTH

Elton Wang
 
T

Tarun Mistry

Hi, thanks for the reply. The UC is already loaded on screen, it is not
dynamic.

I have the following code in my Page class

protected MyUserControl MyUserControlObject;

It is referencing it correctly, however I just cant get the UC to update or
rerender.

FYI to clarify, im trying to get my UC to update when a button is clicked on
the Page, however by the time the button click event is fired, i think my UC
has been rendered :(

Please help.
Thanks

Taz
 
T

Tarun Mistry

You have created the function but have you wired a handler for the event ?
This was indeed the problem! There i was trying to figure out how to se the
onPreRender events lol.

Stupid mistake!

Many thanks,
Kind Regards
Taz
 

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

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top