This is a migrated thread and some comments may be shown as answers.

How to load Controls from RadDock using WebUserControl?

2 Answers 49 Views
Dock
This is a migrated thread and some comments may be shown as answers.
Ian David
Top achievements
Rank 1
Ian David asked on 08 Feb 2013, 12:38 PM
I am having a hard time trying to load my controls inside a RadDock that uses ascx.\

This is my code (it is same as the Portal Demo)

protected void ButtonAddDock_Click(object sender, EventArgs e)
        {
            RadDock dock = CreateRadDock();          
            RadDockZone dz = RadDockZone1;
  
             
            RadDockLayout1.Controls.Add(dock);
            dock.Dock(dz);          
            CreateSaveStateTrigger(dock);
  
            dock.Tag = "Templates/NewQuiz.ascx";
            LoadWidget(dock);
  
        }
private void LoadWidget(RadDock dock)
        {
            if (string.IsNullOrEmpty(dock.Tag) || dock.Closed)
            {
                return;
            }
            Control widget = LoadControl(dock.Tag);
            widget.EnableViewState = false;
            dock.ContentContainer.Controls.Add(widget);
        }
protected void btnSaveDraft_Click(object sender, EventArgs e)
        {
            string[] questions = {};
            int x = 0;
            foreach (RadDock dock in RadDockLayout1.RegisteredDocks)
            {              
                RadTextBox txtQuestion = (RadTextBox)dock.ContentContainer.FindControl("txtQuestion");
                questions[x]= txtQuestion.Text;
                x++;
            }
}

And here is my ASCX

<center style="padding-top: 15px;">
    <table style="text-align: justify;">
        <tr>
            <td style="width: 15%;">
                Question:
            </td>
            <td>
                <telerik:RadTextBox ID="txtQuestion" runat="server" Width="100%">
                </telerik:RadTextBox>
            </td>
        </tr>
        <tr>
            <td style="width: 15%;">
                Help Text:
            </td>
            <td>
                <telerik:RadTextBox ID="txtHelp" runat="server" Width="100%">
                </telerik:RadTextBox>
            </td>
        </tr>
        <tr>
            <td style="width: 15%;">
                Mandatory:
            </td>
            <td>
                <asp:CheckBox ID="chkMandatory" runat="server" />
            </td>
        </tr>
        <tr>
            <td style="width: 15%;">
                Question Weight:
            </td>
            <td>
                <telerik:RadTextBox ID="txtWeight" runat="server" Width="30px" Text="1">
                </telerik:RadTextBox>
            </td>
        </tr>
        <tr>
            <td style="width: 15%;">
                Question Type:
            </td>
            <td>
                <telerik:RadComboBox ID="ddlType" runat="server" AutoPostBack="True">
                    <Items>
                        <telerik:RadComboBoxItem runat="server" Selected="True" Text="--Select Question Type--"
                            Value="--Select Question Type--" />
                        <telerik:RadComboBoxItem runat="server" Text="Multiple Choice - Radio Button" Value="Multiple Choice - Radio Button" />
                        <telerik:RadComboBoxItem runat="server" Text="Multiple Choice - Check Box" Value="Multiple Choice - Check Box" />
                    </Items>
                </telerik:RadComboBox>
            </td>
        </tr>
    </table>
</center>

The code in my aspx can't find the txtQuestion textbox. 

2 Answers, 1 is accepted

Sort by
0
Accepted
Slav
Telerik team
answered on 13 Feb 2013, 08:54 AM
Hi Ian,

The RadTextBox is in the user control that is loaded in the ContentContainer of the RadDock, so you should first get a reference to the user control in order to retrieve the text box. The following code sample will help you do this:
RadTextBox txtQuestion = ((UserControl)dock.ContentContainer.Controls[0]).FindControl("txtQuestion") as RadTextBox;

Greetings,
Slav
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Ian David
Top achievements
Rank 1
answered on 13 Feb 2013, 10:05 AM
Hi Slav,

It worked! Thank you for the reply. So, that is how I can call the controls inside a UserControl. At first I'm trying to do this :

UserControl userControl = (UserControl)dock.FindControl(dock.Tag);
RadTextBox txtQuestion = (RadTextbox)userControl.FindControl("txtQuestion");

But it's not returning any value too. I thought I would never learn how to work on this. Thanks again!

Tags
Dock
Asked by
Ian David
Top achievements
Rank 1
Answers by
Slav
Telerik team
Ian David
Top achievements
Rank 1
Share this question
or