Calling a Method in Parent Page from User Control

calling a method on the parent page from a user control

You could do what casperOne suggested, but I wouldn't advise it. This is tightly coupling your user control to your parent page, which kind of defeats the purpose of a user control.

Personally, I'd add an event to the user control (say, ButtonClicked) that the parent page can handle. In the event handler in your parent, deal with the event however you see fit. This way you can plug the user control into a different page at a later date and not have to worry about logic in the user control that requires a specific kind of parent page.

Invoking a method from the parent page after user control has been loaded?

Get the value at a later page event:

protected override void OnLoadComplete(EventArgs e) {
x = getValueFromUserControl();
}

Unless, of course, there is a specific reason why you must get the value on Page_Load. There are other, probably more appropriate ways to handle this, but without knowing what x is and what you need to do with it, it is hard to give any other advice. For example, maybe the UserControl should fire an event that is handled by the page.

How to call javascript function in the parent page from user control?

I think if you add

ClientIdMode="static"

to your button and take out the OnClientClick="" so it looks like this:

 <asp:LinkButton ID="prevItem" runat="server" ToolTip="previous" Style="color: #000000;" ClientIdMode="static"> << </asp:LinkButton>

and then use onclick directly in the javascript like this:

document.getElementById("prevItem").onclick = function SetProgressBar(){

// some logic

}

That should work...



Related Topics



Leave a reply



Submit