| <telerik:RadWindowManager ReloadOnShow="true" ID="RadWindowManager1" runat="server"> |
| </telerik:RadWindowManager> |
| <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" EnablePageHeadUpdate="False"> |
| <AjaxSettings> |
| <telerik:AjaxSetting AjaxControlID="RadGrid1"> |
| <UpdatedControls> |
| <telerik:AjaxUpdatedControl ControlID="RadGrid1" /> |
| <telerik:AjaxUpdatedControl ControlID="TermCancel_App" /> |
| </UpdatedControls> |
| </telerik:AjaxSetting> |
| </AjaxSettings> |
| </telerik:RadAjaxManager> |
| <telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="DSTerm" GridLines="None"> |
| <MasterTableView AutoGenerateColumns="False" |
| FilterExpression="[ApprovedBy] Is Null AND [ApprovedOn] IS Null AND RemoveFromView =0" |
| DataKeyNames="TermID,Emp_id,Lname" DataSourceID="DSTerminations"> |
| <Columns> |
| <telerik:GridButtonColumn ConfirmDialogType="radWindow" ConfirmText="Continue with termination?" |
| CommandName="Complete" Text="Terminate" /> |
| <telerik:GridButtonColumn ConfirmText="Are you sure you want to cancel?" Text="Cancel" |
| CommandName="Cancel" ConfirmDialogType="RadWindow" UniqueName="column" /> |
| </Columns> |
| </MasterTableView> </RadGrid> |
| Private Property LatestLoadedControlName() As String |
| Get |
| Return CStr(ViewState("LatestLoadedControlName")) |
| End Get |
| Set(ByVal value As String) |
| ViewState("LatestLoadedControlName") = value |
| End Set |
| End Property |
| Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load |
| If Not (LatestLoadedControlName Is Nothing) Then |
| LoadUserControl(LatestLoadedControlName) |
| Else |
| LoadUserControl(ctrls(Request.QueryString("Page"))) |
| End If |
| End Sub |
| Public Sub LoadUserControl(ByVal controlName As String) |
| If Not (LatestLoadedControlName Is Nothing) Then |
| Dim previousControl As Control = Panel1.FindControl(LatestLoadedControlName.Split("."c)(0)) |
| If Not (previousControl Is Nothing) Then |
| Me.Panel1.Controls.Remove(previousControl) |
| End If |
| End If |
| Dim userControlID As String = controlName.Split("."c)(0) |
| Dim targetControl As Control = Panel1.FindControl(userControlID) |
| If targetControl Is Nothing Then |
| Dim userControl As UserControl = CType(Me.LoadControl(controlName), UserControl) |
| 'slashes and tildes are forbidden |
| userControl.ID = userControlID.Replace("/", "").Replace("~", "") |
| Me.Panel1.Controls.Add(userControl) |
| LatestLoadedControlName = controlName |
| End If |
| End Sub |
| Function ctrls(ByVal ItemName As String) As String |
| Dim x As String = "" |
| Select Case ItemName |
| Case "Terminations" |
| x = "TerminationRequests.ascx" |
| Case Else |
| x = "DefaultCtrl.ascx" |
| End Select |
| Return x |
| End Function |
Is it possible to obtain the control object of a child control within a dynamically loaded usercontrol?
Structure:
Website has single master page containing a Telerik ScriptManager and AjaxManager as described in other postings.
User controls contain an AjaxProxyManager and one or more Telerik controls as well as standard controls. There is nothing specific/unique to the Telerik controls, this problem occurs regardless of the control type.
During page_init, required usercontrols are loaded onto the selected page within a placeholder.
Everything works properly- but I need to identify which control within the user controls caused the postback.
I am using a recursive method to search the controls collection within each control (see sample code below).
Following is within the Page_Init()
| If Page.IsPostBack Then |
| 'get the name of the control that caused the postback |
| Dim ctlName As String = Request.Form("__EVENTTARGET") |
| 'find the control |
| Dim thisCtrl As Control = FindControlRecursively(ctlName, Page) |
| End If |
| Public Shared Function FindControlRecursively(ByVal ControlID As String, ByVal ParentControl As Control) As Control |
| Dim c As Control |
| For Each c In ParentControl.Controls |
| Debug.WriteLine(c.ClientID.ToString) |
| If IsNothing(c.ID) = False AndAlso c.ID = ControlID Then |
| Return c |
| Else |
| If c.HasControls Then |
| ' loop through this control collection as well, until we find what we are looking for. |
| Dim foundcontrol As Control = FindControlRecursively(ControlID, c) |
| If IsNothing(foundcontrol) Then |
| Continue For |
| Else |
| Return foundcontrol |
| End If |
| End If |
| End If |
| Next |
| ' if we didn't find the control by now, we aren't going to. |
| Return Nothing |
| End Function |
| Public Shared Function FindChildControl(ByVal start As Control, ByVal id As String) As Control |
| If start IsNot Nothing Then |
| Dim foundControl As Control |
| foundControl = start.FindControl(id) |
| If foundControl IsNot Nothing Then |
| Return foundControl |
| End If |
| For Each c As Control In start.Controls |
| foundControl = FindChildControl(c, id) |
| If foundControl IsNot Nothing Then |
| Return foundControl |
| End If |
| Next |
| End If |
| Return Nothing |
| End Function |
"ctl00$ContentPlaceHolder1$ctl00$lnkMail" where "lnkMail" is the ID of the control and the containing parent controls are those that preceed it. Regardless of the methods used ( .FindControl ) or iterating and comparing .ID, .UniqueID, or .ClientID - none of those values come close to matching and .FindControl never finds it regardless of what I pass (the full name or a subset thereof), even if I identify the correct parent control and invoke .FoundControl on that object. When I iterate through the parent object the .ID values are NULL and the .UniqueID values are ctl00, ctl01, etc.
Using a single webform, .FindControl and either of the recursive functions work as expected. The problem appears to be related to dynamically loading the usercontrols and then trying to locate a child control within the placeholder.
/* START OF CLICKED BUTTON STYLES */
/* Im not sure what the below style is for, but it doesn't seem to affect anything when I comment it out.
I will leave it here in case someone works out what it does.*/
a.radfd_Telerik.radfd_Clicked
{
background-image: url(Button/ButtonSprites.gif);
background-position: 0 -42px;
background-repeat: no-repeat;
}
/* Clicking the button */
a.radfd_Telerik.radfd_Clicked
span, a.radfd_Telerik.radfd_Clicked:hover span
{
background-image: url(Button/ButtonSprites.gif);
color: Black;
font: bold;
font-family: 'Segoe UI' , 'Arial' , 'Helvetica' , 'sans-serif';
font-size: 8pt;
font-weight: bolder;
}
a.radfd_Telerik.radfd_Clicked
.radfdInnerSpan
{
background-position: 0 -63px;
background-repeat: repeat-x;
}
a.radfd_Telerik.radfd_Clicked
.radfdOuterSpan
{
background-position: right -42px;
background-repeat: no-repeat;
}
/* END OF CLICKED BUTTON STYLES */
| protected void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e) |
| { |
| GridEditableItem eeditedItem = e.Item as GridEditableItem; |
| UserControl userControl = (UserControl)e.Item.FindControl(GridEditFormItem.EditFormUserControlID); |
| if (e.Item is GridEditableItem && e.Item.IsInEditMode) |
| { |
| if (!e.Item.OwnerTableView.IsItemInserted) |
| { |
| ImageButton InsertButton = (userControl.FindControl("btnInsert") as ImageButton); |
| InsertButton.Visible = false; |
| if (ViewState["Complete"] == null) |
| { |
| string[] comp = new string[] { }; |
| Session["CompleteID"] = Convert.ToInt32(e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["ID"]); |
| toDoList.ID = Convert.ToInt32(Session["CompleteID"]); |
| comp = toDoList.SelectIsCompleted(); |
| string a = comp[0]; |
| string b = comp[1]; |
| if (a == "True" || b == "true") |
| { |
| TextBox Remarks = (userControl.FindControl("txtRemarks") as TextBox); |
| Remarks.Enabled = false; |
| TextBox task = (userControl.FindControl("txtTask") as TextBox); |
| task.Enabled = false; |
| RadDatePicker AssignDate = (userControl.FindControl("cmbAssignDate") as RadDatePicker); |
| AssignDate.Enabled = false; |
| DropDownList User = (userControl.FindControl("cmbUser") as DropDownList); |
| User.Enabled = false; |
| DropDownList task_cat = (userControl.FindControl("cmbCategory") as DropDownList); |
| task_cat.Enabled = false; |
| RadDatePicker TargetDate = (userControl.FindControl("cmbTargetDate") as RadDatePicker); |
| TargetDate.Enabled = false; |
| ImageButton updateButton = (userControl.FindControl("btnUpdate") as ImageButton); |
| updateButton.Visible = false; |
| ImageButton Complete = (userControl.FindControl("ImageButton4") as ImageButton); |
| Complete.Visible = false; |
| } |
| ViewState["Complete"] = "Filled"; |
| } |
| else |
| { |
| Session["CompleteID"] = null; |
| ViewState["Complete"] = null; |
| } |
| } |
| else |
| { |
| ImageButton updateButton = (userControl.FindControl("btnUpdate") as ImageButton); |
| updateButton.Visible = false; |
| ImageButton Complete = (userControl.FindControl("ImageButton4") as ImageButton); |
| Complete.Visible = false; |
| ImageButton btnDelete = (userControl.FindControl("ImageButton1") as ImageButton); |
| btnDelete.Visible = false; |
| } |
| } |
| else |
| { |
| if (e.Item is GridDataItem) |
| { |
| string Status; |
| Status = objResult.resultDS.Tables[0].Rows[e.Item.ItemIndex]["Status"].ToString(); |
| if (Status == "Completed") |
| { |
| Image flag = (Image)e.Item.FindControl("flag"); |
| flag.ImageUrl = "Images/green.gif"; |
| flag.ToolTip = "Complete"; |
| } |
| else if (Status == "Pending") |
| { |
| Image flag = (Image)e.Item.FindControl("flag"); |
| flag.ImageUrl = "Images/red.gif"; |
| flag.ToolTip = "Pending"; |
| } |
| else |
| { |
| Image flag = (Image)e.Item.FindControl("flag"); |
| flag.ImageUrl = "Images/blue.gif"; |
| flag.ToolTip = "Assigned"; |
| } |
| } |
| } |
| } |
We have only Save and Cancel buttons in our toolbar and it works properly when its position is set at the top. But we would like to move these buttons to the bottom of the editor.
When I set DockingZone="Bottom" in the Tools File with the following editor configuration, deleting some text from the editor reduces the Iframe height to a larget extent (more than what it shoud). Because of this scrollbars get added. When delete button is pressed few more times, editor size shrinks to a non-usable size and eventually errors out when an attempt is made to set a negative height to the iframe element.
<telerik:radeditor
ID="RadEditor1"
runat="server"
EditModes="Design,Html"
AutoResizeHeight="true"
EnableViewState="true"
BorderWidth="0"
Skin="Telerik"
ToolsFile="../RadControls/Editor/ToolsFile.xml"
style="padding:1px;"
EnableResize="false">
<ContextMenus>
<telerik:EditorContextMenu Enabled="false" />
<telerik:EditorContextMenu TagName="IMG" Enabled="false" />
<telerik:EditorContextMenu TagName="TABLE" Enabled="false" />
</ContextMenus>
</telerik:radeditor>
ToolsFile.XML
<root>
<tools name="MainToolbar" DockingZone="Bottom">
<tool name="Save" />
<tool name="Cancel" />
</tools>
</root>
Like I mentioned before, when DockingZone is set to "top" everything works properly.
Please help!
Thanks, Lakshman