I got a user control that has a few links, one of them is "add article". It's placed on top of the ar开发者_StackOverflow社区ticle and bottom of it. When the user clicks on it, the text changes to 'article added'.
But the text only gets changed for one of the links which has been clicked on. How can I make it so that both text changes no matter which one gets clicked?
If you change the text in the user control itself and a postback occurs due to clicking some button on one of the instances only that control will be manipulated. This is just simple default behavior.
If you want other controls to correspond you need to expose an event, raise that in the button click event on the user control and subscribe the underlying page to that event so that it stays in control and can set some property on all instances of the user control to set a certain text.
So:
Button click -> postback -> user control 1 captures click event -> user control 1 raises an event => webform captures this event -> webform sets property of user controls 1 & 2 (which are both instances of the same user control you created) which show the text according to what's passed in via the property.
精彩评论