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

PostBack inside of radgrid add record

4 Answers 137 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kevin
Top achievements
Rank 1
Kevin asked on 01 Apr 2014, 07:40 PM

I have a requirement to postback inside of the radgrid add new record event, What I have is a service that looks up a name, when the user picks a name I want a bunch of labels to be filled out via a postback.  can this be accomplished inside the add record event.  i also use to edit records as well but this is easy to fill.


This si my searcher that needs to post back and fill in labels on the add new record event of the radgrid.
 <EditFormSettings EditFormType="Template">
                                    <FormTemplate>
                                        <table style="width:80%;background-color:antiquewhite;border:double;margin-left:auto;margin:auto">
                                            <tr>
                                                <td>
                                                   <asp:TextBox ID="txtSearch" runat="server" Width="260px" AutoPostBack="true"></asp:TextBox>
                                                    <asp:AutoCompleteExtender ID="txtSearch_ACE" runat="server" DelimiterCharacters="" Enabled="True" ServicePath="~/iMACService.asmx" ServiceMethod="FindName"
                                                    TargetControlID="txtSearch" UseContextkey="true" MinimumPrefixLength="2" OnClientItemSelected="Selected" EnableCaching="true" CompletionInterval="1" />
                                                    <asp:TextBoxWatermarkExtender ID="txtSearch_WME" runat="server" TargetControlID="txtSearch" WatermarkText="Enter Last Name First Name" WatermarkCssClass="WaterMark" />
                                                </td>
                                            </tr>







4 Answers, 1 is accepted

Sort by
0
Accepted
Jayesh Goyani
Top achievements
Rank 2
answered on 02 Apr 2014, 05:11 AM
Hello,

<asp:TextBox ID="txtSearch" runat="server" CausesValidation="false" runat="server" Width="260px" AutoPostBack="true" OnTextChanged="TextBox1_TextChanged" />
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
    TextBox txt = sender as TextBox;
    GridEditFormItem item = txt.NamingContainer as GridEditFormItem;
    // Based on Textbox value get the other information here
    // if your label in FormTemplate then by using below code you can able to fint it
    Label Label1 = item.FindControl("Label1") as Label;
    // Set the label value here
}

Let me know if i am not understand your requirement.

Thanks,
Jayesh Goyani
0
Kevin
Top achievements
Rank 1
answered on 03 Apr 2014, 12:57 PM
Hi jayesh,

Ok tried this but I get and error on the setting of the text, it says it cannot find the control.  It seems that if I am setting the item as gridEditFormItem to the textbox  it will never get the other labels that I need to fill out.  I tried to use a generix grideditformitem but it does not seem to like this either. 

Object reference not set to an instance of an object.   is the error and it hits on the label line.

Protected Sub txtSearch_TextChanged(sender As Object, e As EventArgs)
       If HFPersId.Value > String.Empty Then
           Dim txt As TextBox = TryCast(sender, TextBox)
           Dim item As GridEditFormItem = TryCast(txt.NamingContainer, GridEditFormItem)
 
           Dim Fname As Label = TryCast(item.FindControl("txtFname"), Label)
 
           Fname.Text = "Kevin"
       End If
   End Sub

 

 

 

 

 

0
Princy
Top achievements
Rank 2
answered on 04 Apr 2014, 03:34 AM
Hi Kevin,

Make sure that the label you are trying to set is there in the editform. Here is a code I tried which works fine. Can you share the code where you have labels.

ASPX:
<EditFormSettings EditFormType="Template">
    <FormTemplate>
        <asp:Label ID="txtFname" runat="server" Text="Label"></asp:Label>
        <asp:TextBox ID="txtSearch" runat="server" Width="260px" AutoPostBack="true" OnTextChanged="TextBox1_TextChanged"></asp:TextBox>
    </FormTemplate>
</EditFormSettings>

VB:
Protected Sub TextBox1_TextChanged(sender As Object, e As EventArgs)
    Dim txt As TextBox = TryCast(sender, TextBox)
    Dim item As GridEditableItem = DirectCast(txt.NamingContainer, GridEditableItem)
    Dim Fname As Label = DirectCast(item.FindControl("txtFname"), Label)
    Fname.Text = "Kevin"
End Sub

Thanks,
Princy
0
Kevin
Top achievements
Rank 1
answered on 04 Apr 2014, 02:52 PM
ugh, what a dummy, my fault, Jayesh had it right I was trying to fill a label control that was really a textbox.  thanks for the insight.
Tags
Grid
Asked by
Kevin
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Kevin
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or