开发者

How do I get the instance name of a user control?

I have a user control in .NET 2010. I dragged it on to a page twice. Obviously, both have the same functions. But, depending on which instance was clicked, I want to run the function diffenetly. How can I tell which user control was clicked?

.... Let me add to this. It is a user control with a datalist in it. The data list contains numerous clickable images. When the image is clicked, I am try开发者_StackOverflow中文版ing to grab the name of the instance to use in the code of the user control itself.


Updated To Match Comment

The easiest way would be to use the sender parameter in your event handler. In your case, you should be able to cast to Control and then use the Parent property to get to the actual UserControl:

public void UserControlClickHandler(object sender, EventArgs e)
{
    var senderAsControl = sender as Control;
    var name = senderAsControl.Parent.Name;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜