Click here to Skip to main content
16,016,605 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

In detailview have template field textbox hide/show when other textbox changes
without postback because postback values is not getting for other control.


my code:
HTML
<script type="text/javascript" language="javascript">

       function showhidetextbox(c,f) {

           DetailsView dtlvwActiveList = (DetailsView)Page.Form.FindControl("dtlvwActiveList");

           var text = document.getElementById('<%= dtlvwActiveList.FindControl("txtIIterations").ClientID %>')

           if (text.value == "2") {

               document.getElementById('<%= dtlvwActiveList.FindControl("txtInodayspost").ClientID %>').style.visibility = true;


           }
           else {

                document.getElementById('<%= dtlvwActiveList.FindControl("txtInodayspost").ClientID %>').style.visibility = false;

            }


       }



but it give error object references is not set instacne object.plz help me.
i try out in google but i did not find out solution


and other code for visible design false:

ASP.NET
<asp:TemplateField HeaderText="Iterations (1x – Pre, 2x – Pre & Post, on-going)">

                                                <ItemTemplate>
                                                    <asp:Label ID="lblIterations" runat="server" Text='<%# Bind("Iterations") %>'></asp:Label>
                                                </ItemTemplate>
                                                <EditItemTemplate>
                                                    <asp:TextBox ID="txtEIterations"   runat="server" OnTextChanged="txtEIterations_TextChanged" MaxLength="8" Width="6%" Text='<%# Bind("Iterations") %>'></asp:TextBox>&nbsp;x
                                                    <%--<asp:RegularExpressionValidator ID="revEIterations" runat="server" ControlToValidate="txtEIterations"
                                                        ValidationExpression="[0-9\s]*" ErrorMessage="Iterations should be numeric"></asp:RegularExpressionValidator>--%>
                                                </EditItemTemplate>
                                                <InsertItemTemplate>
                                                    <asp:TextBox ID="txtIIterations" onchange="showhidetextbox(this,this.form)"   runat="server" MaxLength="8" Width="6%" Text='<%# Bind("Iterations") %>'></asp:TextBox>&nbsp;x
                                                   <%-- <asp:RegularExpressionValidator ValidationGroup="InsertGroup" ID="revIIterations" runat="server" ControlToValidate="txtIIterations"
                                                        ValidationExpression="[0-9\s]*" ErrorMessage="Iterations should be numeric"></asp:RegularExpressionValidator>--%>
                                                </InsertItemTemplate>
                                                <ItemStyle CssClass="DetailsViewItemStyle" />
                                            </asp:TemplateField>


<pre lang="xml">&lt;asp:TemplateField HeaderText=&quot;No.of the days for 2x post&quot; Visible=&quot;false&quot;&gt;
                                            &lt;ItemTemplate&gt;
                                             &lt;asp:Label ID=&quot;lblnodayspost&quot; runat=&quot;server&quot; Text=&#39;&lt;%#Bind(&quot;NoOfDays2xPost&quot;) %&gt;&#39;&gt;&lt;/asp:Label&gt;
                                              &lt;/ItemTemplate&gt;

                                            &lt;EditItemTemplate&gt;
                                             &lt;asp:TextBox ID=&quot;txtEnodayspost&quot;  runat=&quot;server&quot; MaxLength=&quot;8&quot; Width=&quot;6%&quot; Text=&#39;&lt;%# Bind(&quot;NoOfDays2xPost&quot;) %&gt;&#39;&gt;&lt;/asp:TextBox&gt;&amp;nbsp;
                                                &lt;asp:RangeValidator ID=&quot;YourERangeValidator&quot; runat=&quot;server&quot;
                                                ControlToValidate=&quot;txtEnodayspost&quot;
                                                ErrorMessage=&quot;Please enter a number between 0-99&quot;
                                                Type=&quot;Integer&quot;
                                                MinimumValue=&quot;0&quot;
                                                MaximumValue=&quot;99&quot;&gt;&lt;/asp:RangeValidator&gt;

                                              &lt;asp:RequiredFieldValidator ID=&quot;rfvtxtEnodayspost&quot; runat=&quot;server&quot; ControlToValidate=&quot;txtEnodayspost&quot;
                                                        Text=&quot;&quot; ErrorMessage=&quot;No of days 2x post is required&quot; Display=&quot;Dynamic&quot;&gt;&lt;/asp:RequiredFieldValidator&gt;
                                            &lt;/EditItemTemplate&gt;



                                            &lt;InsertItemTemplate&gt;
                                              &lt;asp:TextBox ID=&quot;txtInodayspost&quot;   runat=&quot;server&quot; MaxLength=&quot;8&quot; Width=&quot;6%&quot; Text=&#39;&lt;%# Bind(&quot;NoOfDays2xPost&quot;) %&gt;&#39;&gt;&lt;/asp:TextBox&gt;&amp;nbsp;

                                             &lt;asp:RangeValidator ID=&quot;YourIRangeValidator&quot; runat=&quot;server&quot;
                                                ControlToValidate=&quot;txtInodayspost&quot;
                                                ErrorMessage=&quot;Please enter a number between 0-99&quot;
                                                Type=&quot;Integer&quot;
                                                MinimumValue=&quot;0&quot;
                                                MaximumValue=&quot;99&quot; &gt;&lt;/asp:RangeValidator&gt;
                                                 &lt;asp:RequiredFieldValidator ID=&quot;rfvtxtInodayspost&quot; runat=&quot;server&quot; ControlToValidate=&quot;txtInodayspost&quot;
                                                        Text=&quot;&quot; ErrorMessage=&quot;No of days 2x post is required&quot; Display=&quot;Dynamic&quot;&gt;&lt;/asp:RequiredFieldValidator&gt;

                                            &lt;/InsertItemTemplate&gt;



                                              &lt;ItemStyle CssClass=&quot;DetailsViewItemStyle&quot; /&gt;
                                            &lt;/asp:TemplateField&gt;</pre>
Posted
Updated 30-May-14 21:18pm
v3
Comments
On which line you see the Exception? Did you debug?
sadhana4 31-May-14 7:15am    
yes

DetailsView dtlvwActiveList = (DetailsView)Page.Form.FindControl("dtlvwActiveList");
sadhana4 31-May-14 7:16am    
and i also checked but onchange event is not fired.
i checked so many times

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900