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

Accessing controls on pop up from code behind

2 Answers 73 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Berry
Top achievements
Rank 1
Berry asked on 18 Oct 2012, 07:53 PM
Hi,

I am hoping someone on this forum would be able to help me. 

I have a radgrid with Edit form set up as pop up. I am using an "on-click" event for my update/insert buttons on the form template.

However, I am unable to access the controls on the form from the code behind onclick function. Can someone please tell me how I'd be able to access the controls.

Here is my EditForm in my aspx:

  <EditFormSettings InsertCaption="New Request" CaptionDataField="RequestID" EditFormType="Template">
                                            <FormTemplate>
                                                <table id="Table1" cellspacing="1" cellpadding="1" width="800px" border="0" >
                                                    <tr>
                                                        <td colspan="4">
                                                            &nbsp;
                                                        </td>
                                                    </tr>
                                                     <td>
                                                            Request Name:
                                                        </td>
                                                        <td>
                                                            <asp:TextBox ID="txtReqName" runat="server" Text='<%# Bind( "Requ
est_Name") %>' TabIndex="1" >
                                                            </asp:TextBox>
                                                        </td>

                                                    </tr>
                                            
                                                </table>
                                                <table style="width: 100%">
                                                    <tr>
                                                        <td align="center" colspan="2">
                                                            <asp:Button ID="btnUpdate" OnClick = "InsertOrUpdate" Text='<%# Iif (TypeOf Container is GridEditFormInsertItem, "Add", "Update") %>'
                                                                runat="server" CommandName='<%# Iif (TypeOf Container is GridEditFormInsertItem, "Insert", "Update") %>'>
                                                            </asp:Button>&nbsp;
                                                            <asp:Button ID="btnCancel"  OnClick = "CancelUpdate" Text="Cancel" runat="server" CausesValidation="False" CommandName="Cancel">
                                                            </asp:Button>
                                                        </td>
                                                    </tr>
                                                </table>
                                            </FormTemplate>
                                            <PopUpSettings Height="600" Width="800"  CloseButtonToolTip="Cancel" Modal = "true" />
                                        </EditFormSettings>

And here is my code behind:

 Protected Sub InsertOrUpdate(ByVal sender As Object, ByVal e As EventArgs)
' How can I access the control txtReqName here and obtain it's value.
 End Sub

Appreciate any help. Thanks!

2 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 19 Oct 2012, 03:08 AM
Hi Berry,

Please try the following code snippet to access the TextBox in edit form.

VB:
Protected Sub InsertOrUpdate(sender As Object, e As EventArgs)
    Dim btn As Button = DirectCast(sender, Button)
    Dim item As GridEditFormItem = DirectCast(btn.NamingContainer, GridEditFormItem)
    Dim txt As TextBox = DirectCast(item.FindControl("txtReqName"), TextBox)
End Sub

Thanks,
Shinu.
0
Berry
Top achievements
Rank 1
answered on 19 Oct 2012, 05:25 PM
Thanks so much Shinu, that worked!
Tags
Grid
Asked by
Berry
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Berry
Top achievements
Rank 1
Share this question
or