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:

imagemagic add text to image

rem different types of text annotations on existing images rem cyan yellow orange gold rem -gravity SouthWest rem draw text and anno...