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

Get controls in to FormTemplate

3 Answers 12 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Support
Top achievements
Rank 2
Support asked on 30 Apr 2014, 01:09 PM
Hi, we have a grid with FormTemplate; Is possible, with javascript, get textbox and RadDatePicker for set a value?

I want set the textbox value with the name of file uploaded with RadAsyncUpload

This is the code, i get correctly the name of the file. How can i set the textbox txtOggetto with the file name?

<script type="text/javascript">
    function OnClientFileSelected(sender, args) {
        alert(args.get_fileName());
    }
</script>


            <telerik:RadGrid ID="RadGrid1" runat="server"
                CellSpacing="0" Culture="it-IT" GridLines="None" DataKeyNames="ID A"
                DataSourceID="SqlDataSource1" AutoGenerateColumns="false" Width="1000px" AllowSorting="true"
                GroupingSettings-CaseSensitive="false" EnableLinqExpressions="false"
                AllowPaging="true" PageSize="20" OnItemDataBound="RadGrid1_ItemDataBound" OnInsertCommand="RadGrid1_InsertCommand" OnUpdateCommand="RadGrid1_UpdateCommand">
                <MasterTableView DataKeyNames="ID Albo" DataSourceID="SqlDataSource1" CommandItemDisplay="TopAndBottom">
                    <Columns>
                        <telerik:GridEditCommandColumn UniqueName="EditCommandColumn" EditText="Modifica" UpdateText="Aggiorna" InsertText="Inserisci" CancelText="Annulla">
                        </telerik:GridEditCommandColumn>
                        <telerik:GridBoundColumn HeaderText="Categoria" DataField="Descrizione" UniqueName="Descrizione">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="Ultima Modifica" HeaderText="Ultima Modifica" UniqueName="Ultima_Modifica">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="Oggetto" HeaderText="Oggetto" UniqueName="Oggetto">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="Valido Dal" HeaderText="Valido Dal" UniqueName="Valido_Dal" DataFormatString="{0:dd/MM/yyyy}" >
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="Valido Al" HeaderText="Valido Al" UniqueName="Valido_Al" DataFormatString="{0:dd/MM/yyyy}">
                        </telerik:GridBoundColumn>
                    </Columns>
                    <EditFormSettings EditFormType="Template">
                        <FormTemplate>
                            <div style="margin-left:15px;">
                                <div style="height:10px"></div>
<telerik:RadAsyncUpload ID="rupDocumento" runat="server" MaxFileSize="11048576" MaxFileInputsCount="1" Localization-Select="Seleziona" Localization-Cancel="Cancella" Localization-Remove="Rimuovi" AllowedFileExtensions="pdf" OnClientFileSelected="OnClientFileSelected" ></telerik:RadAsyncUpload>
                                <div style="height:10px"></div>
                                <div style="height:10px"></div>
                                <asp:DropDownList ID="DDLCategoria" runat="server" DataTextField="Descrizione" DataValueField="ID Tipo Categoria Albo"></asp:DropDownList>
                                <div style="height:10px"></div>
                                <asp:TextBox ID="txtOggetto" runat="server" MaxLength="255" Text='<%#Eval("Oggetto")%>' Width="400"></asp:TextBox>
                                <div style="height:10px"></div>
                                Validit√†<br />
                                Dal <%=DateTime.Now.ToString("dd/MM/yyyy")%><br />
                                <asp:RadioButton ID="rbNoScad" runat="server" Text="Senza Scadenza" GroupName="Scadenza" /><br />
                                <asp:RadioButton ID="rb15Scad" runat="server" Text="15 giorni" GroupName="Scadenza" /><br />
                                <asp:RadioButton ID="rb30Scad" runat="server" Text="30 giorni" GroupName="Scadenza" /><br />
                                <asp:RadioButton ID="rb60Scad" runat="server" Text="60 giorni" GroupName="Scadenza" /><br />
                                <asp:RadioButton ID="rbFinoAlScad" runat="server" Text="valido fino al" CssClass="sAlign" GroupName="Scadenza" />   <telerik:RadDatePicker ID="rdpAl" runat="server" CssClass="sAlign2"></telerik:RadDatePicker><br />
                                <telerik:RadDatePicker ID="rdpDal" runat="server" Visible="false"></telerik:RadDatePicker>
                            </div>
                            <div style="height:10px"></div>
                            <div style="text-align:center;">
                                <asp:Button ID="btnUpdate" Text='<%# (Container is GridEditFormInsertItem) ? "Inserisci" : "Aggiorna" %>' runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>' ></asp:Button> <asp:Button ID="btnCancel" Text="Annulla" runat="server" CausesValidation="False" CommandName="Cancel" ></asp:Button>
                            </div>
                            <div style="height:10px"></div>
                            <telerik:RadInputManager ID="RadInputManager1" runat="server">
                                </telerik:TextBoxSetting>
                                <telerik:TextBoxSetting BehaviorID="RagExpBehavior2" Validation-IsRequired="true" ErrorMessage="Inserire l'oggetto" EmptyMessage="Oggetto">
                                    <TargetControls>
                                        <telerik:TargetInput ControlID="txtOggetto"></telerik:TargetInput>
                                    </TargetControls>
                                </telerik:TextBoxSetting>
                            </telerik:RadInputManager>
                        </FormTemplate>
                    </EditFormSettings>
                    <SortExpressions>
                        <telerik:GridSortExpression FieldName="ID A" SortOrder="Descending" />
                    </SortExpressions>
                </MasterTableView>
            </telerik:RadGrid>   
            <telerik:RadWindowManager ID="RadWindowManager1" runat="server" EnableShadow="true" KeepInScreenBounds="true"></telerik:RadWindowManager>
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" ProviderName="System.Data.SqlClient" ConnectionString="<%$ ConnectionStrings:StrConnection %>"
                SelectCommand = "SELECT [ID A], [Descrizione], [tStamp], [Oggetto], [Documento], [Cod Categoria], [Ultima Modifica], [Valido Dal], [Valido Al] FROM [Vista_Admin_Albo]">
            </asp:SqlDataSource>

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 02 May 2014, 07:19 AM
Hi,

Please try the following code snippet to get and set the TextBox text in EditForm.

JS:
<script type="text/javascript">
    function OnClientFileSelected(sender, args) {     
        var masterTable = $find("<%= RadGrid1.ClientID %>").get_masterTableView();      
        var txtItem= $telerik.$(masterTable.get_element()).find('input[id*="TextBoxID"]')[0];
        txtItem.innerText = args.get_fileName(); //Set textbox text     
    }
</script>

Thanks,
Princy
0
Support
Top achievements
Rank 2
answered on 02 May 2014, 07:58 AM
Hi, thank you very much for the fast reply.

Your solution work fine. 

Now I'm trying to disable/enable RadDatePicker after a click on RadioButton (always in FormTemplate).

function EnableDateTime() {
    var masterTable = $find("<%= RadGrid1.ClientID %>").get_masterTableView();
    var txtItem = $telerik.$(masterTable.get_element()).find('input[id*="rbFinoAlScad"]')[0];
    var rdpAl = $telerik.$(masterTable.get_element()).find('input[id*="rdpAl"]')[0];
    if (txtItem.checked)
        rdpAl.disabled = true;
    else
        rdpAl.disabled = false;
}

....
 
                    <EditFormSettings EditFormType="Template">
                        <FormTemplate>
                            <div style="margin-left:15px;">
                                <div style="height:10px"></div>
<telerik:RadAsyncUpload ID="rupDocumento" runat="server" MaxFileSize="11048576" MaxFileInputsCount="1" Localization-Select="Seleziona" Localization-Cancel="Cancella" Localization-Remove="Rimuovi" AllowedFileExtensions="pdf" OnClientFileSelected="OnClientFileSelected" ></telerik:RadAsyncUpload>
                                <div style="height:10px"></div>
                                <asp:DropDownList ID="DDLCategoria" runat="server" DataTextField="Descrizione" DataValueField="ID Tipo Categoria Albo"></asp:DropDownList>
                                <div style="height:10px"></div>
                                <asp:TextBox ID="txtOggetto" runat="server" MaxLength="255" Text='<%#Eval("Oggetto")%>' Width="400"></asp:TextBox>
                                <div style="height:10px"></div>
                                Validit√†<br />
                                Dal <%=DateTime.Now.ToString("dd/MM/yyyy")%><br />
                                <asp:RadioButton ID="rbNoScad" runat="server" Text="Senza Scadenza" GroupName="Scadenza" onclick="EnableDateTime()" /><br />
                                <asp:RadioButton ID="rb15Scad" runat="server" Text="15 giorni" GroupName="Scadenza" onclick="EnableDateTime()" /><br />
                                <asp:RadioButton ID="rb30Scad" runat="server" Text="30 giorni" GroupName="Scadenza" onclick="EnableDateTime()" /><br />
                                <asp:RadioButton ID="rb60Scad" runat="server" Text="60 giorni" GroupName="Scadenza" onclick="EnableDateTime()" /><br />
                                <asp:RadioButton ID="rbFinoAlScad" runat="server" Text="valido fino al" CssClass="sAlign" GroupName="Scadenza" onclick="EnableDateTime()" />   <telerik:RadDatePicker ID="rdpAl" runat="server" CssClass="sAlign2" Enabled="false"></telerik:RadDatePicker><br />
                                <telerik:RadDatePicker ID="rdpDal" runat="server" Visible="false"></telerik:RadDatePicker>
                            </div>
                            <div style="height:10px"></div>
                            <div style="text-align:center;">
                                <asp:Button ID="btnUpdate" Text='<%# (Container is GridEditFormInsertItem) ? "Inserisci" : "Aggiorna" %>' runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>' ></asp:Button> <asp:Button ID="btnCancel" Text="Annulla" runat="server" CausesValidation="False" CommandName="Cancel" ></asp:Button>
                            </div>
                            <div style="height:10px"></div>
                            <telerik:RadInputManager ID="RadInputManager1" runat="server">
                                <telerik:TextBoxSetting BehaviorID="RagExpBehavior1" Validation-IsRequired="true" ErrorMessage="Inserire il Protocollo" EmptyMessage="Protocollo">
                                    <TargetControls>
                                        <telerik:TargetInput ControlID="txtProtocollo"></telerik:TargetInput>
                                    </TargetControls>
                                </telerik:TextBoxSetting>
                                <telerik:TextBoxSetting BehaviorID="RagExpBehavior2" Validation-IsRequired="true" ErrorMessage="Inserire l'oggetto" EmptyMessage="Oggetto">
                                    <TargetControls>
                                        <telerik:TargetInput ControlID="txtOggetto"></telerik:TargetInput>
                                    </TargetControls>
                                </telerik:TextBoxSetting>
                            </telerik:RadInputManager>
                        </FormTemplate>
                    </EditFormSettings>
 
 
.....

Why this code don't work fine?
0
Princy
Top achievements
Rank 1
answered on 05 May 2014, 09:34 AM
Hi,

Please try the following JavaScript which works fine at my end.

JavaScript:
function EnableDateTime(sender, args) {
    var grid = $find("<%= RadGrid1.ClientID %>");
    var MasterTable = grid.get_masterTableView();
    var editedItemsArray = MasterTable.get_editItems();
    var editFormItem = editedItemsArray[0].get_editFormItem();
    var radiobtn = $telerik.$(editFormItem).find('input[id*="rbFinoAlScad"]')[0];
    var rdpAl = $telerik.$(editFormItem).find("input[id*='rdpDal']")[0];
    if(radiobtn.checked==false)
        rdpAl.control.set_enabled(false);
    
}

Thanks,
Princy.
Tags
Grid
Asked by
Support
Top achievements
Rank 2
Answers by
Princy
Top achievements
Rank 1
Support
Top achievements
Rank 2
Share this question
or