JavaScript - How to access properties of a texbox which resides in EditItemTemplate from JavaScript?

Asked By chaim mograbi on 12-Sep-12 12:22 PM
 <asp:DetailsView ID="DetailsView1" runat="server" Height="50px" Width="125px" 


AutoGenerateRows="False" DataKeyNames="id" DataSourceID="SqlDataSource1"


AllowPaging="True" >


<Fields>


<asp:BoundField DataField="id" HeaderText="id" InsertVisible="False"


ReadOnly="True" SortExpression="id" />


<asp:TemplateField HeaderText="myRow" SortExpression="myRow">


<EditItemTemplate>


<asp:Label ID="Label2" runat="server" Text="Please type row number:"></asp:Label>


<br />


<asp:TextBox ID="txtRowNumber" runat="server"></asp:TextBox>


<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("myRow") %>'></asp:TextBox>


</EditItemTemplate>


<InsertItemTemplate>


<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("myRow") %>'></asp:TextBox>


</InsertItemTemplate>


<ItemTemplate>


<asp:Label ID="Label1" runat="server" Text='<%# Bind("myRow") %>'></asp:Label>


</ItemTemplate>


</asp:TemplateField>


<asp:CommandField ShowDeleteButton="True" ShowEditButton="True"


ShowInsertButton="True" />


</Fields>


</asp:DetailsView>


<asp:SqlDataSource ID="SqlDataSource1" runat="server"


ConnectionString="<%$ ConnectionStrings:ConnectionString %>"


SelectCommand="SELECT * FROM [Table1]"


DeleteCommand="DELETE FROM [Table1] WHERE [id] = @id"


InsertCommand="INSERT INTO [Table1] ([myRow]) VALUES (@myRow)"


UpdateCommand="UPDATE [Table1] SET [myRow] = @myRow WHERE [id] = @id">


<DeleteParameters>


<asp:Parameter Name="id" Type="Int32" />


</DeleteParameters>


<InsertParameters>


<asp:Parameter Name="myRow" Type="String" />


</InsertParameters>


<UpdateParameters>


<asp:Parameter Name="myRow" Type="String" />


<asp:Parameter Name="id" Type="Int32" />


</UpdateParameters>


</asp:SqlDataSource>

// My question: How to access txtRowNumber from JavaScript? Thanks


Jitendra Faye replied to chaim mograbi on 13-Sep-12 01:37 AM
Refer my article-

http://steptodotnet.blogspot.in/2011/12/accessing-gridview-controls-using.html
chaim mograbi replied to Jitendra Faye on 13-Sep-12 04:36 AM
Thank you very much
chaim mograbi replied to Jitendra Faye on 13-Sep-12 06:41 AM

AnonymousSeptember 13, 2012 3:35 AM

Thank you for this post.
When i try it i get microsoft JScript runtime error:'$'
is undefined.
I tried to code document.getElementById instead of '$'.
what i got was:
microsoft JScript runtime error:Unable to get value of the property 'hide': object is null or undefined.
many thanks

Jitendra Faye replied to chaim mograbi on 13-Sep-12 07:23 AM
for this add jquery pluin to your page, follow this link for steps-

http://steptodotnet.blogspot.in/2011/12/jquery-popup-window-in-aspnet.html

Try this and let me know;
chaim mograbi replied to Jitendra Faye on 13-Sep-12 11:44 AM
It works fine, thank you.
Using this technic, is it possible to access properties of a textbox inside EditItemTemplate?
Thank you very much