By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,320 Members | 2,212 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,320 IT Pros & Developers. It's quick & easy.

Can a user control call a method in the 'parent' aspx page?

P: n/a
I have a page that my users will go to to upload files to my website.
As I want to reuse the file upload code on multiple pages I put the
file upload textbox/buttons on a user control which I plan to include
in multiple aspx pages where they'll be able to upload images for other
purposes.

On the first page that I'm working on where users will be doing the
upload (which I'll call the 'parent' page) I also have a DataGrid where
I display the images that the user has already uploaded. The problem
I'm running into is that the code that hits the database and binds the
dataset to the DataGrid only runs when the page loads for the first
time. And I can't determine how to call my DataBind method from the
method in my user control that runs when a person actually uploads a
new image.

So the image does get uploaded but the DataGrid doesn't refresh
displaying the most recent image that's just been added.

I can re-write my code to not use a user control. I'd have similar code
repeated multiple times in 3 or 4 .aspx pages (which I'd like to
avoid.)

Any ideas? Can you call a method in an aspx.cs page from the
code-behind of a user control included in that page?

Jan 3 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
You should easily be able to get the parent page from the Parent
property on your control. You can then cast this instance of the control to
the type of the parent page and then access whatever you need to from there.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

<en*****@yahoo.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
I have a page that my users will go to to upload files to my website.
As I want to reuse the file upload code on multiple pages I put the
file upload textbox/buttons on a user control which I plan to include
in multiple aspx pages where they'll be able to upload images for other
purposes.

On the first page that I'm working on where users will be doing the
upload (which I'll call the 'parent' page) I also have a DataGrid where
I display the images that the user has already uploaded. The problem
I'm running into is that the code that hits the database and binds the
dataset to the DataGrid only runs when the page loads for the first
time. And I can't determine how to call my DataBind method from the
method in my user control that runs when a person actually uploads a
new image.

So the image does get uploaded but the DataGrid doesn't refresh
displaying the most recent image that's just been added.

I can re-write my code to not use a user control. I'd have similar code
repeated multiple times in 3 or 4 .aspx pages (which I'd like to
avoid.)

Any ideas? Can you call a method in an aspx.cs page from the
code-behind of a user control included in that page?

Jan 3 '06 #2

P: n/a
Nicolas, I'm just adding a small piece of code :-)

public class YourControlClass : UserControl
{
override protected OnLoad(EventArgs e)
{
// Casts the Page property to the desired type and access the method
((YourPageClass) this.Page).YourMethod();
}
}

--
With regards
Anders Borum / SphereWorks
Microsoft Certified Professional (.NET MCP)
Jan 3 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.