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

Cannot get textbox.text from EditFormSettings of Radgrid1

5 Answers 139 Views
Grid
This is a migrated thread and some comments may be shown as answers.
James
Top achievements
Rank 1
James asked on 12 Jul 2011, 11:34 PM

I cannot retrieve the textbox.text from from Editformsettings of the Radgrid1. The string returns empty all the time. What is wrong with the code after researching seems that the way i am doing it is correct. Any suggestions will be appreciated.


CODEBEHIND:

Protected Sub RadGrid1_ItemCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.ItemCommand

 

 

If e.CommandName = "PerformInsert" Then

 

 

 

 

 

 

If (TypeOf e.Item Is GridEditFormItem AndAlso e.Item.IsInEditMode) Then

 

 

 

 

 

 

Dim editItem As GridEditFormItem = DirectCast(e.Item, GridEditFormItem)

 

 

Dim Mytab As TextBox = DirectCast(editItem.FindControl("tbTabName"), TextBox)

 

 

Dim LocalTab As New SWBC.Weblet.BO.Mortgage.MtgTabs

 

 

        With LocalTab

 

                .TabName = Mytab.Text

 

 

 

 

 

 

 

 

        End With

 

 

 

 

 

    MyTabsList.Add(LocalTab)

 

End If

 

 

 

 

 

 

End If

 

 

 



ASPX Page

 

 

<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" >

 

 

 

<AjaxSettings>

 

 

<telerik:AjaxSetting AjaxControlID="RadGrid1">

 

 

<UpdatedControls>

 

 

<telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1" />

 

 

 

 

 

 

</UpdatedControls>

 

 

</telerik:AjaxSetting>

 

 

</AjaxSettings>

 

 

 

 

 

 

</telerik:RadAjaxManager>

 

 

 

 

 

 

 

 

<telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" >

 

 

</telerik:RadAjaxLoadingPanel>

 

 

 

 

 

 

 

<telerik:RadGrid ID="RadGrid1" runat="server" AllowFilteringByColumn="false" AutoGenerateColumns="true"

 

 

AllowPaging="true" AllowSorting="true" Skin="Vista" Width="50%" GridLines="Both"

 

 

PageSize="50" EnableViewState="true" OnInsertCommand="RadGrid1_InsertCommand" >

 

 

 

 

 

 

<ExportSettings ExportOnlyData="true" IgnorePaging="true" OpenInNewWindow="true" >

 

 

 

 

 

 

<Csv RowDelimiter="Comma" />

 

 

</ExportSettings>

 

 

 

 

 

 

<ClientSettings AllowDragToGroup="True">

 

 

 

 

 

 

<Selecting AllowRowSelect="True" />

 

 

 

 

 

 

<Scrolling AllowScroll="True" UseStaticHeaders="true" />

 

 

</ClientSettings>

 

 

 

 

 

 

 

 

<MasterTableView AutoGenerateColumns="false" CommandItemDisplay="top" Height="100%" GridLines="Both"

 

 

 

 

 

 

EditMode="PopUp" DataKeyNames="Count" >

 

 

 

 

 

 

<RowIndicatorColumn>

 

 

 

 

 

 

<HeaderStyle Width="20px"/>

 

 

</RowIndicatorColumn>

 

 

 

 

 

 

<CommandItemSettings AddNewRecordText="Add Tab" />

 

 

<ExpandCollapseColumn>

 

 

 

 

 

 

<HeaderStyle Width="20px" />

 

 

</ExpandCollapseColumn>

 

 

 

 

 

 

 

<Columns>

 

 

 

 

 

 

 

<telerik:GridEditCommandColumn HeaderStyle-Width="20px" >

 

 

 

 

 

 

</telerik:GridEditCommandColumn>

 

 

 

 

 

 

<telerik:GridBoundColumn DataField="Count" DataType="System.Int16" HeaderText="Item" ReadOnly="True" SortExpression="Item">

 

 

 

 

 

 

<ItemStyle Width="20px" HorizontalAlign="Center" />

 

 

 

 

 

 

<HeaderStyle Width="20px" HorizontalAlign="Center" />

 

 

</telerik:GridBoundColumn>

 

 

<telerik:GridBoundColumn DataField="TabName" DataType="system.string" HeaderText="TabName" ReadOnly="True" SortExpression="TabName">

 

 

 

 

 

 

<ItemStyle Width="120px" HorizontalAlign="Center" />

 

 

 

 

 

 

<HeaderStyle Width="120px" HorizontalAlign="Center" />

 

 

</telerik:GridBoundColumn>

 

 

 

 

 

 

<telerik:GridBoundColumn DataField="TabText" HeaderText="TabText" SortExpression="TabText" UniqueName="TabText">

 

 

 

 

 

 

</telerik:GridBoundColumn>

 

 

<telerik:GridButtonColumn CommandName="Delete" Text="Delete" UniqueName="column" HeaderStyle-Width="50px" ItemStyle-Width="50px">

 

 

 

 

 

 

</telerik:GridButtonColumn>

 

 

 

 

 

 

 

 

</Columns>

 

 

<EditFormSettings InsertCaption="Add New Tab" EditFormType="Template" >

 

 

 

 

 

 

<PopUpSettings Width="640" />

 

 

 

 

 

 

 

<FormTemplate >

 

 

<table id="Table1" cellspacing="1" cellpadding="10" border="0" width="660">

 

 

 

 

 

 

<tr>

 

 

 

 

 

 

<td ></td>

 

 

<td> <asp:HiddenField runat="server" ID="hdCount" Value='<%# Bind( "Count" ) %>' /></td>

 

 

 

 

 

 

</tr>

 

 

 

 

 

 

<tr>

 

 

 

 

 

 

 

<td >Tab Name:</td>

 

 

<td>

 

 

 

 

 

 

 

 

<asp:TextBox runat="server" ID="tbTabName" Text='<%# Bind( "TabName" ) %>'>

 

 

</asp:TextBox>

 

 

 

 

</td>

 

 

</tr>

 

 

 

 

 

 

<tr>

 

 

 

 

 

 

<td valign="top">Tab Text:</td>

 

 

 

<td>

 

 

 

 

 

 

<telerik:RadEditor runat="server" ID="txtBody" Width="525px" >

 

 

 

 

 

 

<Tools>

 

 

<telerik:EditorToolGroup >

 

 

 

 

 

 

<telerik:EditorTool Name=AjaxSpellCheck />

 

 

 

 

 

 

<telerik:EditorTool Name=findandreplace />

 

 

 

 

 

 

<telerik:EditorTool Name=SelectAll />

 

 

<telerik:EditorTool Name=copy />

 

 

 

 

 

 

<telerik:EditorTool Name=Cut Visible=true />

 

 

<telerik:EditorTool Name=paste/>

 

 

 

 

 

 

<telerik:EditorToolStrip Name="paste options" >

 

 

 

 

 

 

<telerik:EditorTool Name=pasteashtml />

 

 

 

 

 

 

<telerik:EditorTool Name=pastefromword />

 

 

 

 

 

 

<telerik:EditorTool Name=pastefromwordnofontsnosizes />

 

 

</telerik:EditorToolStrip>

 

 

<telerik:EditorTool Name=undo />

 

 

 

 

 

 

<telerik:EditorTool Name=redo />

 

 

</telerik:EditorToolGroup>

 

 

<telerik:EditorToolGroup >

 

 

 

 

 

 

<telerik:EditorTool Name=linkmanager />

 

 

<telerik:EditorTool Name=unlink />

 

 

</telerik:EditorToolGroup>

 

 

 

 

 

 

<telerik:EditorToolGroup >

 

 

 

 

 

 

<telerik:EditorTool Name=insertparagraph />

 

 

<telerik:EditorTool Name=inserthorizontalrule />

 

 

<telerik:EditorTool Name=insertdate />

 

 

<telerik:EditorTool Name=InsertTime />

 

 

</telerik:EditorToolGroup>

 

 

 

 

 

 

<telerik:EditorToolGroup >

 

 

 

 

 

 

<telerik:EditorTool Name=formatblock />

 

 

<telerik:EditorTool Name=fontname />

 

 

<telerik:EditorTool Name=fontsize />

 

 

</telerik:EditorToolGroup>

 

 

 

 

 

 

<telerik:EditorToolGroup >

 

 

 

 

 

 

<telerik:EditorTool Name=bold />

 

 

<telerik:EditorTool Name=italic />

 

 

<telerik:EditorTool Name=underline />

 

 

<telerik:EditorTool Name=strikethrough />

 

 

 

 

 

 

 

</telerik:EditorToolGroup>

 

 

 

 

 

 

<telerik:EditorToolGroup >

 

 

 

 

 

 

<telerik:EditorTool Name=justifyleft />

 

 

<telerik:EditorTool Name=justifycenter />

 

 

<telerik:EditorTool Name=justifyright />

 

 

<telerik:EditorTool Name=justifynone />

 

 

 

 

 

 

 

</telerik:EditorToolGroup>

 

 

 

 

 

 

<telerik:EditorToolGroup >

 

 

 

 

 

 

<telerik:EditorTool Name=indent />

 

 

<telerik:EditorTool Name=outdent />

 

 

</telerik:EditorToolGroup>

 

 

 

 

 

 

<telerik:EditorToolGroup >

 

 

 

 

 

 

<telerik:EditorTool Name=insertorderedlist />

 

 

<telerik:EditorTool Name=insertunorderedlist />

 

 

</telerik:EditorToolGroup>

 

 

 

 

 

 

<telerik:EditorToolGroup >

 

 

 

 

 

 

<telerik:EditorTool Name=toggletableborder />

 

 

</telerik:EditorToolGroup>

 

 

 

 

 

 

<telerik:EditorToolGroup >

 

 

 

 

 

 

<telerik:EditorTool Name=forecolor />

 

 

<telerik:EditorTool Name=backcolor />

 

 

<telerik:EditorTool Name=formatstripper />

 

 

</telerik:EditorToolGroup>

 

 

 

 

 

 

<telerik:EditorToolGroup >

 

 

 

 

 

 

<telerik:EditorTool Name=insertsymbol />

 

 

<telerik:EditorTool Name=inserttable />

 

 

 

</telerik:EditorToolGroup>

 

 

 

 

 

 

<telerik:EditorToolGroup >

 

 

 

 

 

 

<telerik:EditorTool Name=converttolower />

 

 

<telerik:EditorTool Name=converttoupper />

 

 

<telerik:EditorTool Name=zoom />

 

 

<telerik:EditorTool Name=ModuleManager />

 

 

<telerik:EditorTool Name=togglescreenmode />

 

 

</telerik:EditorToolGroup>

 

 

</Tools>

 

 

 

 

 

 

</telerik:RadEditor>

 

 

</td>

 

 

 

 

 

 

</tr>

 

 

 

 

 

 

 

</table>

 

 

<table width="623">

 

 

<tr>

 

 

 

 

 

 

<td align="right" colspan="2">

 

 

 

 

 

 

<asp:Button ID="Button1" Text='<%# Iif (TypeOf Container is GridEditFormInsertItem, "Insert", "Update") %>'

 

 

runat="server" CommandName='<%# Iif (TypeOf Container is GridEditFormInsertItem, "PerformInsert", "Update") %>'>

 

 

 

 

 

 

</asp:Button>&nbsp;

 

 

 

 

 

 

<asp:Button ID="Button2" Text="Cancel" runat="server" CausesValidation="False" CommandName="Cancel">

 

 

 

 

 

 

</asp:Button>

 

 

 

 

 

 

</td>

 

 

 

 

 

 

</tr>

 

 

 

 

 

 

</table>

 

 

 

 

 

 

 

 

 

 

 

 

</FormTemplate>

 

 

</EditFormSettings>

 

 

 

 

 

 

</MasterTableView>

 

 

 

 

 

 

</telerik:RadGrid>


 

 

 

 

5 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 13 Jul 2011, 04:29 AM
Hello James,

Try the following code snippet in ItemCommand to access textbox in FormTemplate.

VB:
Protected Sub RadGrid1_ItemCommand(sender As Object, e As GridCommandEventArgs)
    If e.CommandName = "PerformInsert" Then
        Dim editform As GridEditFormItem = DirectCast(DirectCast(e.Item, Telerik.Web.UI.GridDataItem).EditFormItem, GridEditFormItem)
        Dim txtbx As TextBox = DirectCast(editform.FindControl("tbTabName"), TextBox)
        Dim strtxt As String = txtbx.Text
    End If
End Sub

Thanks,
Princy.
0
James
Top achievements
Rank 1
answered on 13 Jul 2011, 07:30 PM
princy this is not working i get the following error:

unable to cast object of type telerik web.ui.Grideditforminsertitem to type telerik.web.ui.griddataitem

Can anyone else offer assistance on this.

Thanks,

James
0
Elliott
Top achievements
Rank 2
answered on 13 Jul 2011, 08:04 PM
instead of
Dim Mytab As TextBox = DirectCast(editItem.FindControl("tbTabName"), TextBox)
try
Dim Mytab As TextBox = DirectCast(editItem("tbTabName").Controls(0), TextBox)

FindControl wasn't working for me
0
James
Top achievements
Rank 1
answered on 14 Jul 2011, 09:15 PM
Marianne,

Using Firebug on my firefox webrowser I do see that the  value is being retained on the post back but i am losing it when the page reloads. I have set the enablestateview property on the webpage, radgrid and control to = true. Still to no avial am i able to obtain the value on the RadGrid1_ItemCommand() function. Do you have any ideas how to maintain the value on the postback?

Thanks,

James Arriaga
0
Iana Tsolova
Telerik team
answered on 20 Jul 2011, 11:55 AM
Hi James,

I reviewed the posts in this thread and I can confirm the code suggested to you is proper. However as it did not help in your case, I suggest that you open a formal support ticket and send us a runnable sample illustrating your scenario and the unexpected behavior.

Kind regards,
Iana
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

Tags
Grid
Asked by
James
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
James
Top achievements
Rank 1
Elliott
Top achievements
Rank 2
Iana Tsolova
Telerik team
Share this question
or