[RESOLVED] should a WebControl be disposed or not?
In my gridview rowdatabound event I have the following code
Code:
if (e.Row.RowType == DataControlRowType.DataRow) {
line_item item = e.Row.DataItem as line_item;
if (!item.active)
(e.Row.FindControl("linkName") as HyperLink).CssClass = "inactive";
(e.Row.FindControl("linkName") as HyperLink).NavigateUrl = "someUrl.aspx?id=" +
item.id;
//do some more stuff with linkName
}
To improve its readablity in changed it to
Code:
if (e.Row.RowType == DataControlRowType.DataRow) {
line_item item = e.Row.DataItem as line_item;
HyperLink linkName = (e.Row.FindControl("linkName") as HyperLink);
if (!item.active)
linkName.CssClass = "inactive";
linkName.NavigateUrl = "someUrl.aspx?id=" + item.id;
//do some more stuff with linkName
// linkName.Dispose(); ????
}
My question, should the created Hyperlink 'linkName' be disposed or not?
Re: should a WebControl be disposed or not?
Not required. You are just creating a reference to an object that has already been created and you don't need to dispose off an object that is used in the page.
HyperLink linkName = (e.Row.FindControl("linkName") as HyperLink);
, isn't this statement same as
Code:
string s1 = "It's me";
//s2 is actually referring to s1 :)
string s2 = s1;
Re: should a WebControl be disposed or not?