Wednesday, August 11, 2004

Prevent User Control Code from running (ASP.NET)

You can prevent code within a user control (ascx file) from running if it is invisible on the containing page. To do so, just check base.Visible (C#) or MyBase.Visible (VB). For example:


private void Page_Load(object sender, EventArgs e)
	if (base.Visible) {
		// run code


Private Sub Page_Load(sender As Object, e As EventArgs)
	If MyBase.Visible Then
		' run code
	End If
End Sub

No comments: