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

Unable to get values from UserControl

7 Answers 253 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jason
Top achievements
Rank 2
Jason asked on 26 Sep 2008, 02:37 PM
Hi, I'm using a WebUserControl as my insert/edit form in a RadGrid and when I try and get the values from the controls on the WebUserControl they are all coming back as empty strings (in the case of a text box) any ideas as to what I may be doing wrong? The code I'm using follows below, any help would be appreciated; thanks!


Web Page
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="channeleditor.aspx.cs" Inherits="Nemo.management.ventriloservers.channeleditor" MasterPageFile="~/resources/site.master" %> 
<asp:Content ID="Body" ContentPlaceHolderID="HtmlBody" runat="server"
    <div class="ControlPanelContainer"
        <telerik:RadAjaxPanel ID="ChannelsManagementPanel" runat="server"
        <p> 
            <asp:Label ID="lblServerID" runat="server" Text="Server ID:" AssociatedControlID="tbxServerID" /> 
            <telerik:RadNumericTextBox ID="tbxServerID" runat="server" NumberFormat-AllowRounding="false" NumberFormat-DecimalDigits="0" NumberFormat-GroupSizes="9" /> 
            <asp:ImageButton ID="ConnectServer" runat="server" ImageAlign="Middle" ImageUrl="~/resources/images/icons/connect.gif" OnClick="ConnectServer_Click" /> 
            <asp:ImageButton ID="DisconnectServer" runat="server" ImageAlign="Middle" ImageUrl="~/resources/images/icons/disconnect.gif" OnClick="DisconnectServer_Click" Visible="false" /> 
        </p> 
        <telerik:RadGrid ID="ChannelsList" runat="server" AutoGenerateColumns="false" Skin="Black" Width="95%"  
            OnItemDataBound="ChannelsList_ItemDataBound" OnInsertCommand="ChannelsList_InsertCommand"
            <MasterTableView AllowAutomaticInserts="true" AllowAutomaticDeletes="true" AllowAutomaticUpdates="true" EditMode="EditForms" 
                CommandItemDisplay="Top" HierarchyDefaultExpanded="false" DataKeyNames="ID,ParentID" FilterExpression="ParentID = Guid.Empty"
                <CommandItemSettings AddNewRecordImageUrl="../../resources/images/icons/channel_add.gif" AddNewRecordText="New Channel" RefreshText="" /> 
                <CommandItemStyle Font-Names="Tahoma" Font-Bold="false" Font-Size="10pt" /> 
                <HeaderStyle Font-Names="Tahoma" Font-Bold="true" Font-Size="10pt" ForeColor="Gray" /> 
                <ItemStyle Font-Names="Tahoma" Font-Bold="false" Font-Size="10pt" /> 
                <AlternatingItemStyle Font-Names="Tahoma" Font-Bold="false" Font-Size="10pt" BackColor="#3B3B3B" /> 
                <Columns> 
                    <telerik:GridButtonColumn UniqueName="AddSubChannel" ButtonType="ImageButton" ImageUrl="~/resources/images/icons/add.gif" CommandName="InitInsert" CommandArgument="SubChannel"
                        <ItemStyle Width="3%" HorizontalAlign="Center" /> 
                    </telerik:GridButtonColumn> 
                    <telerik:GridButtonColumn UniqueName="EditChannel" ButtonType="ImageButton" ImageUrl="~/resources/images/icons/edit.gif" CommandName="Edit"
                        <ItemStyle Width="3%" HorizontalAlign="Center" /> 
                    </telerik:GridButtonColumn> 
                    <telerik:GridBoundColumn UniqueName="DisplayName" HeaderText="Display Name" DataField="Name"
                        <ItemStyle Width="35%" /> 
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn UniqueName="Comment" HeaderText="Comment" DataField="Comment"
                        <ItemStyle Width="29%" /> 
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn UniqueName="ProtectionMode" HeaderText="Protection Mode" DataField="ProtMode"
                        <ItemStyle Width="15%" /> 
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn UniqueName="VoiceMode" HeaderText="Voice Mode" DataField="VoiceMode"
                        <ItemStyle Width="15%" /> 
                    </telerik:GridBoundColumn> 
                </Columns> 
                <SelfHierarchySettings KeyName="ID" ParentKeyName="ParentID" /> 
                <EditFormSettings EditFormType="WebUserControl" UserControlName="~/resources/controls/newchannel.ascx"
 
                </EditFormSettings> 
            </MasterTableView> 
        </telerik:RadGrid> 
        </telerik:RadAjaxPanel> 
    </div> 
</asp:Content> 

Web Page Code:
using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using TypeFrag.Hosting; 
using Telerik.Web.UI; 
 
namespace Nemo.management.ventriloservers 
    public partial class channeleditor : System.Web.UI.Page 
    { 
        protected List<string> protectedModes = new List<string>(); 
        protected List<string> voiceModes = new List<string>(); 
 
        protected void Page_Load(object sender, EventArgs e) 
        { 
            if (!IsPostBack) 
            { 
                tbxServerID.Enabled = true
                ConnectServer.Visible = true
                DisconnectServer.Visible = false
            } 
 
            protectedModes.Add(ProtectedMode.OpenToPublic.ToString()); 
            protectedModes.Add(ProtectedMode.ChannelPassword.ToString()); 
            protectedModes.Add(ProtectedMode.UserAuthorization.ToString()); 
 
            voiceModes.Add(VoiceMode.Normal.ToString()); 
            voiceModes.Add(VoiceMode.Queued.ToString()); 
            voiceModes.Add(VoiceMode.Muted.ToString()); 
 
            //tbxServerID.Text = "36920"; // Rick's test server 
            tbxServerID.Text = "12248"// User server with a lot of channels, DO NOT EDIT 
            ConnectServer_Click(nullnull); 
        } 
 
        protected void ConnectServer_Click(object sender, ImageClickEventArgs e) 
        { 
            int serverID; 
 
            if (int.TryParse(tbxServerID.Text, out serverID)) 
            { 
                ControlPanelInterface cpi = new ControlPanelInterface(serverID); 
                ChnFile channelsFile = cpi.GetChannels(); 
                Session.Add("ChannelsFile", channelsFile); 
 
                tbxServerID.Enabled = false
                ConnectServer.Visible = false
                DisconnectServer.Visible = true
 
                InitializeEditor(); 
            } 
        } 
 
        protected void DisconnectServer_Click(object sender, ImageClickEventArgs e) 
        { 
 
        } 
 
        protected void InitializeEditor() 
        { 
            ChnFile channelsFile = Session["ChannelsFile"as ChnFile; 
             
            ChannelsList.DataSource = channelsFile.Channels; 
            ChannelsList.DataBind(); 
        } 
 
        protected void ChannelsList_ItemDataBound(object sender, GridItemEventArgs e) 
        { 
            if (e.Item is GridDataItem) 
            { 
                GridDataItem dataItem = e.Item as GridDataItem; 
                if (dataItem["ProtectionMode"].Text == ProtectedMode.OpenToPublic.ToString()) 
                { 
                    dataItem["ProtectionMode"].Text = "Open to Public"
                } 
                else if (dataItem["ProtectionMode"].Text == ProtectedMode.ChannelPassword.ToString()) 
                { 
                    dataItem["ProtectionMode"].Text = "Channel Password"
                } 
                else if (dataItem["ProtectionMode"].Text == ProtectedMode.UserAuthorization.ToString()) 
                { 
                    dataItem["ProtectionMode"].Text = "User Authorization"
                } 
            } 
        } 
 
        protected void ChannelsList_InsertCommand(object sender, GridCommandEventArgs e) 
        { 
            GridEditableItem editedItem = e.Item as GridEditableItem; 
            UserControl insertForm = (UserControl)e.Item.FindControl(GridEditFormItem.EditFormUserControlID); 
 
            ChnFile channelsFile = Session["ChannelsFile"as ChnFile; 
            Channel newChannel = new Channel(); 
            newChannel.Name = (insertForm.FindControl("tbxDisplayName"as RadTextBox).Text; 
            newChannel.Phonetic = (insertForm.FindControl("tbxPhoneticName"as RadTextBox).Text; 
            newChannel.Comment = (insertForm.FindControl("tbxComment"as RadTextBox).Text; 
            newChannel.AllowRecording = GetBOOL((insertForm.FindControl("ckAllowRecording"as CheckBox).Checked); 
            newChannel.AllowPaging = GetBOOL((insertForm.FindControl("ckAllowPaging"as CheckBox).Checked); 
            newChannel.AllowTtsBinds = GetBOOL((insertForm.FindControl("ckAllowTTSBinds"as CheckBox).Checked); 
            newChannel.PhantomMode = GetBOOL((insertForm.FindControl("ckAllowPhantoms"as CheckBox).Checked); 
            newChannel.AllowCrossChannelXmit = GetBOOL((insertForm.FindControl("ckAllowCrossChanXmit"as CheckBox).Checked); 
            newChannel.AllowWaveBinds = GetBOOL((insertForm.FindControl("ckAllowWaveBinds"as CheckBox).Checked); 
            newChannel.AllowU2U = GetBOOL((insertForm.FindControl("ckAllowU2UTransmit"as CheckBox).Checked); 
            newChannel.AllowGuestToJoin = GetBOOL((insertForm.FindControl("ckAllowGuests"as CheckBox).Checked); 
 
            if ((insertForm.FindControl("tbxPassword"as RadTextBox).Text.Trim().Length > 0) 
            { 
                newChannel.EncPassChan = TypeFrag.Hosting.Password.Hash((insertForm.FindControl("tbxPassword"as RadTextBox).Text); 
            } 
 
            string protectedMode = (insertForm.FindControl("cboProtectedMode"as RadComboBox).SelectedValue; 
            if (protectedMode == ProtectedMode.OpenToPublic.ToString()) 
            { 
                newChannel.ProtMode = ProtectedMode.OpenToPublic; 
            } 
            else if (protectedMode == ProtectedMode.UserAuthorization.ToString()) 
            { 
                newChannel.ProtMode = ProtectedMode.UserAuthorization; 
            } 
            else if (protectedMode == ProtectedMode.ChannelPassword.ToString()) 
            { 
                newChannel.ProtMode = ProtectedMode.ChannelPassword; 
            } 
 
            string voiceMode = (insertForm.FindControl("cboVoiceMode"as RadComboBox).SelectedValue; 
            if (voiceMode == VoiceMode.Muted.ToString()) 
            { 
                newChannel.VoiceMode = VoiceMode.Muted; 
            } 
            else if (voiceMode == VoiceMode.Normal.ToString()) 
            { 
                newChannel.VoiceMode = VoiceMode.Normal; 
            } 
            else if (voiceMode == VoiceMode.Queued.ToString()) 
            { 
                newChannel.VoiceMode = VoiceMode.Queued; 
            } 
 
            newChannel.ExemptFromInactivity = GetBOOL((insertForm.FindControl("ckIgnoreInactivity"as CheckBox).Checked); 
            newChannel.DisableSoundEvts = GetBOOL((insertForm.FindControl("ckDisableSoundEvents"as CheckBox).Checked); 
            newChannel.TimeLimit = int.Parse((insertForm.FindControl("tbxTransmitTimeLimit"as RadNumericTextBox).Text); 
            newChannel.RankLevel = int.Parse((insertForm.FindControl("tbxTransmitRankLevel"as RadNumericTextBox).Text); 
            newChannel.MaxClients = int.Parse((insertForm.FindControl("tbxMaxClients"as RadNumericTextBox).Text); 
             
            channelsFile.Channels.Add(newChannel); 
            Session["ChannelsFile"] = channelsFile; 
 
            ChannelsList.DataSource = channelsFile.Channels; 
            ChannelsList.DataBind(); 
        } 
 
        private bool GetBoolean(BOOL b) 
        { 
            if (b.ToString() == "TRUE" || b.ToString() == "1"
            { 
                return true
            } 
            else 
            { 
                return false
            } 
        } 
 
        private BOOL GetBOOL(bool b) 
        { 
            if (b) 
            { 
                return BOOL.TRUE; 
            } 
            else 
            { 
                return BOOL.FALSE; 
            } 
        } 
    } 
 

Web User Control Code:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="newchannel.ascx.cs" Inherits="Nemo.resources.controls.newventrilouser" %> 
 
<table width="520px" style="font-family:Tahoma;font-size:10pt;font-weight:normal;border-collapse:collapse;" rules="none"
    <tr class="EditFormHeader"
        <td colspan="5">Create New Channel</td> 
    </tr> 
    <tr> 
        <td align="right" style="width:40%;"><asp:Label ID="lblDisplayName" AssociatedControlID="tbxDisplayName" Text="Display Name:" runat="server" /></td
        <td colspan="4" style="width:60%;"
            <telerik:RadTextBox ID="tbxDisplayName" runat="server" Skin="Gray" MaxLength="255" Width="200px" /> 
        </td> 
    </tr> 
    <tr> 
        <td align="right" style="width:40%;"><asp:Label ID="lblPhoneticName" AssociatedControlID="tbxPhoneticName" Text="Phonetic Name:" runat="server" /></td
        <td colspan="4" style="width:60%;"
            <telerik:RadTextBox ID="tbxPhoneticName" runat="server" Skin="Gray" MaxLength="255" Width="200px" /> 
        </td> 
    </tr> 
    <tr> 
        <td align="right" style="width:40%;"><asp:Label ID="lblComment" AssociatedControlID="tbxComment" Text="Comment:" runat="server" /></td
        <td colspan="4" style="width:60%;"
            <telerik:RadTextBox ID="tbxComment" runat="server" Skin="Gray" MaxLength="255" Width="200px" /> 
        </td> 
    </tr> 
    <tr> 
        <td align="right" style="width:40%;"><asp:Label ID="lblPassword" AssociatedControlID="tbxPassword" Text="Channel Password:" runat="server" /></td
        <td colspan="4" style="width:60%;"
            <telerik:RadTextBox ID="tbxPassword" runat="server" Skin="Gray" MaxLength="255" Width="200px" TextMode="Password" /> 
        </td> 
    </tr> 
    <tr> 
        <td style="width:40%;"></td> 
        <td align="left" colspan="2" style="width:30%;font-size:8pt;"
            <asp:CheckBox ID="ckAllowRecording" Text="Allow Recording" runat="server" /> 
        </td> 
        <td align="left" colspan="2" style="width:30%;font-size:8pt;"
            <asp:CheckBox ID="ckAllowCrossChanXmit" Text="Allow Cross-Chan Transmit" runat="server" /> 
        </td> 
    </tr> 
    <tr> 
        <td style="width:40%;"></td> 
        <td align="left" colspan="2" style="width:30%;font-size:8pt;"
            <asp:CheckBox ID="ckAllowPaging" Text="Allow Paging" runat="server" /> 
        </td> 
        <td align="left" colspan="2" style="width:30%;font-size:8pt;"
            <asp:CheckBox ID="ckAllowWaveBinds" Text="Allow Wave File Bind" runat="server" /> 
        </td> 
    </tr> 
    <tr> 
        <td style="width:40%;"></td> 
        <td align="left" colspan="2" style="width:30%;font-size:8pt;"
            <asp:CheckBox ID="ckAllowTTSBinds" Text="Allow TTS Binds" runat="server" /> 
        </td> 
        <td align="left" colspan="2" style="width:30%;font-size:8pt;"
            <asp:CheckBox ID="ckAllowU2UTransmit" Text="Allow U2U Transmit" runat="server" /> 
        </td> 
    </tr> 
    <tr> 
        <td style="width:40%;"></td>     
        <td align="left" colspan="2" style="width:30%;font-size:8pt;"
            <asp:CheckBox ID="ckAllowPhantoms" Text="Allow Phantoms" runat="server" /> 
        </td> 
        <td align="left" colspan="2" style="width:30%;font-size:8pt;"
            <asp:CheckBox ID="ckAllowGuests" Text="Allow Guest Accounts" runat="server" /> 
        </td> 
    </tr> 
    <tr> 
        <td style="width:40%;"></td>     
        <td align="left" colspan="2" style="width:30%;font-size:8pt;"
            <asp:CheckBox ID="ckAllowVoiceTargets" Text="Allow Voice Targets" runat="server" /> 
        </td> 
        <td align="left" colspan="2" style="width:30%;font-size:8pt;"
            <asp:CheckBox ID="ckAllowCommandingTargets" Text="Allow Cmding Targets" runat="server" /> 
        </td> 
    </tr> 
    <tr>    
        <td align="right" style="width:40%;"
            <asp:Label ID="lblProtectedMode" Text="Protected Mode:" runat="server" /> 
        </td> 
        <td colspan="4" style="width:60%;"
            <telerik:RadComboBox ID="cboProtectedMode" runat="server" Skin="Gray" Width="200px"
                <Items> 
                    <telerik:RadComboBoxItem Text="Open to Public" Value="OpenToPublic" /> 
                    <telerik:RadComboBoxItem Text="Channel Password" Value="ChannelPassword" /> 
                    <telerik:RadComboBoxItem Text="User Authorization" Value="UserAuth" /> 
                </Items> 
            </telerik:RadComboBox> 
        </td> 
    </tr> 
    <tr> 
        <td align="right" style="width:40%;"
            <asp:Label ID="lblVoiceMode" Text="Voice Mode:" runat="server" /> 
        </td> 
        <td colspan="4" style="width:60%;"
            <telerik:RadComboBox ID="cboVoiceMode" runat="server" Skin="Gray" Width="200px"
                <Items> 
                    <telerik:RadComboBoxItem Text="Normal" Value="Normal" /> 
                    <telerik:RadComboBoxItem Text="Queued" Value="Queued" /> 
                    <telerik:RadComboBoxItem Text="Muted" Value="Muted" /> 
                </Items> 
            </telerik:RadComboBox> 
        </td> 
    </tr> 
    <tr> 
        <td align="right" style="width:40%;"
            <asp:Label ID="lblChannelCodec" Text="Channel Codec/Format:" runat="server" /> 
        </td> 
        <td colspan="4" style="width:60%;"
            <telerik:RadComboBox ID="cboChannelCodec" runat="server" Skin="Gray" Width="200px"
            </telerik:RadComboBox> 
        </td> 
    </tr> 
    <tr> 
        <td colspan="2" style="width:50%;"
            <asp:CheckBox ID="ckIgnoreInactivity" Text="Exempt from Inactivity Timers" runat="server" /> 
        </td> 
        <td colspan="3" align="right" style="width:50%;"
            <asp:Label ID="lblTransmitTimeLimit" Text="Transmit Time Limit:" runat="server" /> 
            <telerik:RadNumericTextBox ID="tbxTransmitTimeLimit" Skin="Gray" NumberFormat-AllowRounding="false" NumberFormat-DecimalDigits="0" runat="server" Width="25px" /> 
        </td> 
    </tr> 
    <tr> 
        <td colspan="2" style="width:50%;"
            <asp:CheckBox ID="ckDisableGuestXmit" Text="Disable Guest Account Transmit" runat="server" /> 
        </td> 
        <td colspan="3" align="right" style="width:50%;"
            <asp:Label ID="lblTransmitRankLevel" Text="Transmit Rank Level (0-100):" runat="server" /> 
            <telerik:RadNumericTextBox ID="tbxTransmitRankLevel" Skin="Gray" NumberFormat-AllowRounding="false" NumberFormat-DecimalDigits="0" MaxValue="100" runat="server" Width="25px" /> 
        </td> 
    </tr> 
    <tr> 
        <td colspan="2" style="width:50%;"
            <asp:CheckBox ID="ckDisableSoundEvents" Text="Disable Sound Events" runat="server" /> 
        </td> 
        <td colspan="3" align="right" style="width:50%;"
            <asp:Label ID="lblMaxClients" Text="Max Clients:" runat="server" /> 
            <telerik:RadNumericTextBox ID="tbxMaxClients" Skin="Gray" NumberFormat-AllowRounding="false" NumberFormat-DecimalDigits="0" runat="server" Width="25px" /> 
        </td> 
    </tr> 
    <tr> 
        <td colspan="3" style="padding-top:15px;"></td> 
        <td align="right" style="padding-top:15px;"
            <asp:LinkButton ID="btnInsert" Text="Create" runat="server" CommandName="PerformInsert" /> 
        </td> 
        <td align="right" style="padding-top:15px;"
            <asp:LinkButton ID="btnCancel" Text="Cancel" runat="server" CommandName="Cancel" CausesValidation="false" /> 
        </td> 
    </tr> 
</table>    

7 Answers, 1 is accepted

Sort by
0
Jason
Top achievements
Rank 2
answered on 26 Sep 2008, 02:44 PM
Also, I have tried both GridEditFormItem.EditFormUserControlID and GridEditFormInsertItem.EditFormUserControlID
0
Iana Tsolova
Telerik team
answered on 29 Sep 2008, 11:50 AM
Hi Jason,

Find more information about RadGrid custom edit modes in the following resources:
http://www.telerik.com/help/aspnet-ajax/grdcustomeditforms.html
http://www.telerik.com/DEMOS/ASPNET/prometheus/Grid/Examples/DataEditing/UserControlEditForm/DefaultVB.aspx

Let us know if this helps and if you need further directions.

All the best,
Iana
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Jason
Top achievements
Rank 2
answered on 30 Sep 2008, 11:43 AM
Thanks Iana, I had actually modeled the code after the example to no avail. I have since resolved the problem by explicitly defining the AutoEventWireup property on the page.

Thanks, Jason
0
Michael Nagy
Top achievements
Rank 2
answered on 27 Oct 2008, 08:45 AM
Hello all .

i have usercontrol for Rad grid  EditFormSettings

i follow the example it was great ..
http://www.telerik.com/help/aspnet-ajax/grdcustomeditforms.html
http://www.telerik.com/DEMOS/ASPNET/prometheus/Grid/Examples/DataEditing/UserControlEditForm/DefaultVB.aspx

but i have some problem i want to set the Grid value into the text box in user control in example <asp:TextBox id="TextBox7" runat="server"
Text='<%# DataBinder.Eval( Container, "DataItem.Country" ) %>'>


but i want to do this in c# not in acax file  ?????
0
Sebastian
Telerik team
answered on 27 Oct 2008, 08:51 AM
Hi Michael,

To achieve your goal you can intercept the ItemDataBound event of the grid as demonstrated in the help topic pointed below:

http://www.telerik.com/help/aspnet-ajax/grdcustomeditforms.html (paragraph 'Setting properties without using binding expressions')

Best regards,
Stephen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Michael Nagy
Top achievements
Rank 2
answered on 27 Oct 2008, 09:15 AM
thanks for quickly replay ..
great answer but i asked if there is another way to get the dataitem on usercontrol code behind (C#) . and set the usercontrols value at the user control c# file not in the page that contain grid
0
Sebastian
Telerik team
answered on 27 Oct 2008, 09:32 AM
Hello Michael,

Inside the ItemDataBound handler of the grid you can reference the parent item instance and demonstrated in the code snippets from the documentation resource and extract the value from a cell of your choice using column unique names. Review the implementation from the article for more details.

Best regards,
Stephen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
Jason
Top achievements
Rank 2
Answers by
Jason
Top achievements
Rank 2
Iana Tsolova
Telerik team
Michael Nagy
Top achievements
Rank 2
Sebastian
Telerik team
Share this question
or