Unable to get values from UserControl

8 posts, 0 answers
  1. Jason
    Jason avatar
    9 posts
    Member since:
    Sep 2008

    Posted 26 Sep 2008 Link to this post

    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
    1 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="channeleditor.aspx.cs" Inherits="Nemo.management.ventriloservers.channeleditor" MasterPageFile="~/resources/site.master" %> 
    2 <asp:Content ID="Body" ContentPlaceHolderID="HtmlBody" runat="server"
    3     <div class="ControlPanelContainer"
    4         <telerik:RadAjaxPanel ID="ChannelsManagementPanel" runat="server"
    5         <p> 
    6             <asp:Label ID="lblServerID" runat="server" Text="Server ID:" AssociatedControlID="tbxServerID" /> 
    7             <telerik:RadNumericTextBox ID="tbxServerID" runat="server" NumberFormat-AllowRounding="false" NumberFormat-DecimalDigits="0" NumberFormat-GroupSizes="9" /> 
    8             <asp:ImageButton ID="ConnectServer" runat="server" ImageAlign="Middle" ImageUrl="~/resources/images/icons/connect.gif" OnClick="ConnectServer_Click" /> 
    9             <asp:ImageButton ID="DisconnectServer" runat="server" ImageAlign="Middle" ImageUrl="~/resources/images/icons/disconnect.gif" OnClick="DisconnectServer_Click" Visible="false" /> 
    10         </p> 
    11         <telerik:RadGrid ID="ChannelsList" runat="server" AutoGenerateColumns="false" Skin="Black" Width="95%"  
    12             OnItemDataBound="ChannelsList_ItemDataBound" OnInsertCommand="ChannelsList_InsertCommand"
    13             <MasterTableView AllowAutomaticInserts="true" AllowAutomaticDeletes="true" AllowAutomaticUpdates="true" EditMode="EditForms" 
    14                 CommandItemDisplay="Top" HierarchyDefaultExpanded="false" DataKeyNames="ID,ParentID" FilterExpression="ParentID = Guid.Empty"
    15                 <CommandItemSettings AddNewRecordImageUrl="../../resources/images/icons/channel_add.gif" AddNewRecordText="New Channel" RefreshText="" /> 
    16                 <CommandItemStyle Font-Names="Tahoma" Font-Bold="false" Font-Size="10pt" /> 
    17                 <HeaderStyle Font-Names="Tahoma" Font-Bold="true" Font-Size="10pt" ForeColor="Gray" /> 
    18                 <ItemStyle Font-Names="Tahoma" Font-Bold="false" Font-Size="10pt" /> 
    19                 <AlternatingItemStyle Font-Names="Tahoma" Font-Bold="false" Font-Size="10pt" BackColor="#3B3B3B" /> 
    20                 <Columns> 
    21                     <telerik:GridButtonColumn UniqueName="AddSubChannel" ButtonType="ImageButton" ImageUrl="~/resources/images/icons/add.gif" CommandName="InitInsert" CommandArgument="SubChannel"
    22                         <ItemStyle Width="3%" HorizontalAlign="Center" /> 
    23                     </telerik:GridButtonColumn> 
    24                     <telerik:GridButtonColumn UniqueName="EditChannel" ButtonType="ImageButton" ImageUrl="~/resources/images/icons/edit.gif" CommandName="Edit"
    25                         <ItemStyle Width="3%" HorizontalAlign="Center" /> 
    26                     </telerik:GridButtonColumn> 
    27                     <telerik:GridBoundColumn UniqueName="DisplayName" HeaderText="Display Name" DataField="Name"
    28                         <ItemStyle Width="35%" /> 
    29                     </telerik:GridBoundColumn> 
    30                     <telerik:GridBoundColumn UniqueName="Comment" HeaderText="Comment" DataField="Comment"
    31                         <ItemStyle Width="29%" /> 
    32                     </telerik:GridBoundColumn> 
    33                     <telerik:GridBoundColumn UniqueName="ProtectionMode" HeaderText="Protection Mode" DataField="ProtMode"
    34                         <ItemStyle Width="15%" /> 
    35                     </telerik:GridBoundColumn> 
    36                     <telerik:GridBoundColumn UniqueName="VoiceMode" HeaderText="Voice Mode" DataField="VoiceMode"
    37                         <ItemStyle Width="15%" /> 
    38                     </telerik:GridBoundColumn> 
    39                 </Columns> 
    40                 <SelfHierarchySettings KeyName="ID" ParentKeyName="ParentID" /> 
    41                 <EditFormSettings EditFormType="WebUserControl" UserControlName="~/resources/controls/newchannel.ascx"
    42  
    43                 </EditFormSettings> 
    44             </MasterTableView> 
    45         </telerik:RadGrid> 
    46         </telerik:RadAjaxPanel> 
    47     </div> 
    48 </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>    

  2. Jason
    Jason avatar
    9 posts
    Member since:
    Sep 2008

    Posted 26 Sep 2008 Link to this post

    Also, I have tried both GridEditFormItem.EditFormUserControlID and GridEditFormInsertItem.EditFormUserControlID
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Iana Tsolova
    Admin
    Iana Tsolova avatar
    3388 posts

    Posted 29 Sep 2008 Link to this post

    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.
  5. Jason
    Jason avatar
    9 posts
    Member since:
    Sep 2008

    Posted 30 Sep 2008 Link to this post

    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
  6. Michael Nagy
    Michael Nagy avatar
    18 posts
    Member since:
    May 2008

    Posted 27 Oct 2008 Link to this post

    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  ?????
  7. Sebastian
    Admin
    Sebastian avatar
    9934 posts

    Posted 27 Oct 2008 Link to this post

    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.
  8. Michael Nagy
    Michael Nagy avatar
    18 posts
    Member since:
    May 2008

    Posted 27 Oct 2008 Link to this post

    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
  9. Sebastian
    Admin
    Sebastian avatar
    9934 posts

    Posted 27 Oct 2008 Link to this post

    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017