I want to add RadEditor dynamically. It is getting added to the page but as soon as postback occurs i get Multiple controls with the same ID 'EditorRibbonBarResourcesHolder' were found. Below is the code that i am using to add control dynamically.
RadEditor editor = new RadEditor();
editor.ID = "editor_" + itemTypeattribute.ItemAttributeID + rand.Next();
cellAttributeValue.Controls.Add(editor);
editor.DialogOpener.ID = "editor_dialopOpener_" + itemTypeattribute.ItemAttributeID;
editor.DialogOpener.Window.ID = "editor_dialopOpener_window_"+ ItemTypeattribute.ItemAttributeID;
editor.ClientIDMode = ClientIDMode.AutoID;
editor.EnableEmbeddedScripts = true;
editor.Height = 200;
Any help is appreciated. Thanks
Whenever I need to use a radeditor "dynamically" I have it on the page from the start with visible=false and then show it when I need it.
Related
I am trying to add a cmseditableregion to my Kentico webpart that exists inside of tabbed content, now the amount of tabs are flexible so I would like to generate this dynamically. I have tried the method that follows (stringbuilder) but it just renders it as html and not as a control when passed to a literal.
for (int i = 1; i <= TabCount; i++)
{
sb.AppendLine("<li class=\"htab-list__item--fininfo active\">");
sb.AppendLine("<a href=\"#financial-result\" class=\"htab-list__link tab-link\">");
sb.AppendLine("<cms:CMSEditableRegion runat=\"server\" id=\"ttl" + i.ToString() + "\" RegionType=\"Textbox\" RegionTitle=\"" + i.ToString() + " Title\" />");
sb.AppendLine("</li>");
Is there a way to make the CMSEditableRegion be able to be set dynamically in the code so that when the loop builds the page code it will be in the right spot as a control and not just html.
The full code has more html and 3 editable regions per loop but it wont even work with just one.
Adding control dynamically is done as follows:
// Let's assume that 'plc' is a placeholder. But it can be any control.
plc.Controls.Add(new LiteralControl("<li class=\"htab-list__item--fininfo active\">"));
plc.Controls.Add(new LiteralControl("<a href=\"#financial-result\" class=\"htab-list__link tab-link\">"));
plc.Controls.Add(new CMSEditableRegion { ID = "someid", RegionType = CMSEditableRegionTypeEnum.TextBox, RegionTitle = "sometitle" });
plc.Controls.Add(new LiteralControl("</li>"));
Also check out MSDN.
I suggest you to create an ad hoc PageType (called DocumentType in Kentico 7) where you can put the HTML text needed. Then you can display it using a Repeater web part or a ASP.NET repeater if, like me, you prefer to work in code.
I'm new to developing with C# and asp.net. I am trying to laod five images onto my web form I also need to do it code behind and not just drag and drop. I can't get them to work. I have tried:
dicePic[i] = new System.Web.UI.WebControls.Image();
//dicePic[0] = Image.FromFile(HttpContext.Current.Server.MapPath("/images/1.gif"));
I also set the properties like this:
dicePic[0].ID = "Dice1";
dicePic[0].Style["position"] = "absolute";
dicePic[0].Style["top"] = "80px";
dicePic[0].Style["left"] = "80px";
dicePic[0].Visible = true;
dicePic[0].Width = 50;
dicePic[0].Height = 50;
dicePic[0].ImageUrl = "~/images/1.gif";//HttpContext.Current.Server.MapPath("/images/1.gif");
dicePic[0].Controls.Add(dicePic[0]);
Any help would be great. Thanks
replace this line :dicePic[0].Controls.Add(dicePic[0]); by this.Controls.Add(dicePic[0]);
You should add it to a container in your page (or to the page itself).
if you are doing this inside a Page put
this.Controls.Add(dicePic[i]);
after
dicePic[i] = new System.Web.UI.WebControls.Image();
I've got an asp.net page with some CollapsiblePanelExtender which is collapsed by default and contains CheckBoxes.
My problem is that when I expand one and check a CheckBox an AutoPostBack event is firing and my CollapsiblePanelExtender is collapsed again.
Is there a way to let the CollapsiblePanelExtender expand when I click a CheckBox with just C# and asp.net? I don't want to use JavaScript here.
Here is the configuration of my control:
CollapsiblePanelExtender cpe = new CollapsiblePanelExtender();
cpe.ID = "cpe" + headerName;
cpe.TargetControlID = headerName + "Body";
cpe.CollapsedSize = 0;
cpe.Collapsed = true;
cpe.ExpandControlID = headerName + "Header";
cpe.CollapseControlID = headerName + "Header";
cpe.AutoCollapse = false;
cpe.AutoExpand = false;
cpe.ScrollContents = false;
cpe.ExpandDirection = CollapsiblePanelExpandDirection.Vertical;
cpe.SuppressPostBack = false;
It collapses because the html is replaced with what comes from the server after the postback, therefore, the CollapsiblePanelExtender returns to the default state.
If you can use UpdatePanels, consider the following:
Put the CollapsiblePanelExtender inside an UpdatePanel. Set the UpdatePanel UpdateMode="Conditional" and ChildrenAsTriggers="false".
The client state of the html inside that updatepanel will be maintained after the Postback because the panel will not update.
If you ever need it to update, you could update it manually by calling updatePanel.Update().
I've got a problem with adding some controls into a Panel(which gets "PopUpped" by a ModalPopupExtender) and add a CheckedChanged-EventHandler.
First of all, when user clicks on a button, this happens inside the CreatePanelChoose() function:
foreach (ListItem item in lbSupplier.Items)
{
string cbid = "cb" + i;
CheckBox cb = new CheckBox();
cb.ID = cbid;
cb.Text = item.Text;
cb.AutoPostBack = true;
AjaxControlToolkit.MutuallyExclusiveCheckBoxExtender mecbe = new AjaxControlToolkit.MutuallyExclusiveCheckBoxExtender();
mecbe.ID = "mecbe" + cbid;
mecbe.TargetControlID = cbid;
mecbe.Key = "SupplierKEY";
mecbe.BehaviorID = mecbe.ID + i;
//Also adding a Label
phModalPopupExtender.Controls.Add(new LiteralControl("</br>")); //phModalPopupExtender is a PlaceHolder
phModalPopupExtender.Controls.Add(cb);
phModalPopupExtender.Controls.Add(mecbe);
phModalPopupExtender.Controls.Add(lbl);
AsyncPostBackTrigger trigger = new AsyncPostBackTrigger();
trigger.ControlID = cbid;
trigger.EventName = "CheckedChanged";
UpdatePanelMatrix.Triggers.Add(trigger);
i++;
ButtonOK.Enabled = false;
}
lblText.Text = "Select one Supplier";
ModalPopupExtender1.Show();
Then i add the EventHandler in the Page_LoadComplete:
As you can see it also gets asigned to the control (I think).
The ModalPopup shows up correctly, but if I click one of the CheckBox, then it just closes it without going into cb_CheckedChanged, but it makes a Async postback ...
If I check Request.Form["__ASYNCPOST"] its true and Request.Form["__EVENTTARGET"] is also correct. (It gives me the unique id!)
Request.Form["__EVENTARGUMENT"] is empty.
I think I also need to say that I use a masterpage.
The problem shouldn't be the lifecycle of the page, because msdn says:
LoadComplete
Raised at the end of the event-handling stage.
Use this event for tasks that require that all other controls on the page be loaded.
Its the onliest place it makes me think it would be right.
Btw: yes i looked trough the topics here allready, but nothing helped me ... (google fo sure also)
Edit 1:
if (IsPostBack)
{
if (recreating == true)
{
CreatePanelChoose();
}
}
In CreatePanelChoose i do the foreach now everytime when its a postback! But it still doesnt fire cb_ChangedChecked ...
Edit 2:
MSDN-Page-Lifecycle also says:
PreInit
Raised after the start stage is complete and before the initialization
stage begins.
Use this event for the following:
Create or re-create dynamic controls.
So i tried to recreate the Panel there. But i dont have the ListItems there to get the values ... ?!
Okay, gave up ...
If someone would still have an answer, it would be great!
Right now I dont use the OnCheckedChanged-Event of the CheckBoxes anymore.
I just let them select a CheckBox and on the OnClick of the ButtonOk I loop through the CheckBoxes and check which one is selected.
I need to load a silverlight application in a portion of an aspx page on a button click on that page page. Some init parameters need to be passed to the silverlight application based on the user inputs on the host page on button click. How to do that?
I presume I need to create the silverlight object from code-behind to set custom InitParameters. Any idea how to do that?
Extending to what is mentioned here, you can do something like this:
HtmlGenericControl myHtmlObject = new HtmlGenericControl("object");
myHtmlObject.Attributes["data"] = "data:application/x-silverlight-2";
myHtmlObject.Attributes["type"] = "application/x-silverlight-2";
myHtmlObject.Attributes["width"] = "100%";
myHtmlObject.Attributes["height"] = "100%";
this.Page.Controls.Add(myHtmlObject);
HtmlGenericControl mySourceParam = new HtmlGenericControl("param");
mySourceParam.Attributes["name"] = "source";
mySourceParam.Attributes["value"] = "ClientBin/MySilverlightApplication.xap";
myHtmlObject.Controls.Add(mySourceParam);
HtmlGenericControl myOnErrorParam = new HtmlGenericControl("param");
myOnErrorParam .Attributes["name"] = "onError";
myOnErrorParam .Attributes["value"] = "onSilverlightError";
myHtmlObject.Controls.Add(myOnErrorParam);
HtmlGenericControl myInputParam = new HtmlGenericControl("param");
myOnErrorParam .Attributes["name"] = "InitParameters";
myOnErrorParam .Attributes["value"] = "param1=Hello,param2=World";
myHtmlObject.Controls.Add(myInputParam);
this.Page.Controls.Add(myHtmlObject);