Frage

I have a page with a private variable: AccountData.

This handles all of the account data and I save it in the viewstate between postbacks.
I have a User Control named AccountFavorites that renders all of the account Favorite topics.

When a user decides he wants to cancel one favorite topic he clicks on an asp:LinkButton and it posts back to the server to change the value in the Database.

However, the Control doesn't know what AccountData is, only the page does.

How can I use the AccountData in a postback of the Control?

Can I make the postback go to the page instead?

War es hilfreich?

Lösung 2

Since it is page that owns/parents the user control, it is preferable to for the page to know about the specifics of the control, not the other way around. Add AccountData property to the control and in the page's Page_Load do:

uc.AccountData = AccountData;

Andere Tipps

<myprefix:AccountFavorites runat="server" id="TheAccountFavorites" />

In your page set the info...

protected void Page_Load(object sender, EventArgs e)
{
    TheAccountFavorites.TheAccountData=MyAccountData;//assuming you'll load up MyAccountData
}

In your control, expose AccountData as a public property. This will allow you to access it from the page.

public AccountData TheAccountData {get;set;}

This is assuming AccountData was the type name and not something else, like a string. But you can change AccountData to string and it will work.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top