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:

C#

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

VB

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

Comments

Popular posts from this blog

Select box manipulation with jQuery

iTextSharp: Generating a Basic PDF file (ASP.NET/C#)

Popup Window Countdown (JavaScript)