Tuesday

Load controls in asp.net dynamically

1.Add placeholder to .aspx
<asp:Panel ID="PlaceHolderPanel" runat="server">
</asp:Panel>

2. add control loading code to codebehind :
string AlreadyLoaded=null;
private void loadControl(string ctr){
if (!string.IsNullOrEmpty(ctr) && AlreadyLoaded!=ctr ) {
Control ctrl = LoadControl(ctr);
ctrl.ID="ctr1";
PlaceHolderPanel.Controls.Clear();
PlaceHolderPanel.Controls.Add(ctrl);
ControlName = ctr;
AlreadyLoaded=ctr;
}

}

protected void Page_Load(object sender, EventArgs e){
loadControl("~/Controls/mycontrol.ascx");
}


There are limitations for loaded controls , one of them using onPreRender rather then Page_load:

// 1.call all functions in prerender only
protected override void OnPreRender(EventArgs e){
SetFilterValues();
Bind();
base.OnPreRender(e);
}

No comments:

test smtp server with powershell

Send-MailMessage -SMTPServer smtp.domain.com -To [email protected] -From [email protected] -Subject "This is a test email" -Body ...