views:

24

answers:

1

I designed my page with an htmlinputtext as follows

  <asp:TemplateField>
                    <ItemTemplate>
                        <asp:Label ID="lblTrialPeriodEnds" runat="server" Text='<%# Eval("trialPeriodEnds","{0:dd/MM/yyyy}") %>'></asp:Label>
                    </ItemTemplate>
                    <HeaderTemplate>
                        TrialPeriodEnds
                    </HeaderTemplate>
                    <EditItemTemplate>
                    <input type="text"  name="testinput" class="textbox" value='<%# Eval("trialPeriodEnds") %>'
                            id="txtEffectiveDate" runat="server" />
                        <a onclick="showCalendarControl('txtEffectiveDate')" href="#">
                            <img alt="cal" src="calendar.gif" style="width: 20px; height: 20px" border="0" /></a>
  </EditItemTemplate>
                </asp:TemplateField>

My code in rowupdating is as follows

       HtmlInputText htmInput = (HtmlInputText)GridView1.Rows[e.RowIndex].FindControl("Daily");
     strExpiry = htmInput.Value;

I am getting an error as Object reference not set to an instance of an object.

Why it is displaying can any on tell

+4  A: 

The input that you are using is an HTML input tag. In order for ASP.NET to see this tag, you must include a runat="server" attribute. This will indicate to ASP.NET that it should track the tag and you will be able to interact with it from your code. Without this tag, ASP.NET does not know about the control and therefore it does not show up when you call FindControl.

Note that when you make ASP.NET aware of the control, it will may modify the ID. This is so that ASP.NET ensures that each control has a unique ID. Your example has the control within a GridView, so the input control's ID will be modified so that ASP.NET knows that the control is a child of the GridView. You will need to modify any client side scripting to be aware of the new ID. I caution against checking the ID in HTML and then simply assigning the new ID as modifications of the ASP.NET structure can change the ID. You mentioned in your comment that you are using jQuery. I would recommend using a class and have jQuery assign the control based on the class of the input control.

sgriffinusa
But adding runt="Server" is not raising my calendar
Dorababu
Not sure what you mean. There is no calendar in the code that you have posted.
sgriffinusa
I used a calendar to popup using Jquery when i clicked inside the textbox if i use runat="Server" i am not going to get that one
Dorababu
See my updated answer.
sgriffinusa
I have modified my question can u please look and tell what to do now
Dorababu
You really should ask an separate question for this issue. It is completely different from the question you initially asked.
sgriffinusa