0

ASCX page markup:

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="DateInput.ascx.cs" Inherits="CustomControls_DateInput" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajx" %>


<div class="input-group" style="width: 250px;">
    <asp:TextBox ID="txb_dt1" runat="server" CssClass="form-control" ></asp:TextBox>
    <span class="input-group-btn">
        <asp:LinkButton ID="lb_caller" runat="server" CausesValidation="false" CssClass="btn btn-default btn-sm">
            <span class="glyphicon glyphicon-calendar"></span>
        </asp:LinkButton>
    </span>
</div>
<ajx:CalendarExtender runat="server" ID="cal1" TargetControlID="txb_dt1" PopupButtonID="lb_caller" Format="MMM dd, yyyy"></ajx:CalendarExtender>

my aspx

  <asp:TemplateField HeaderText="Tanggal Kirim" SortExpression="tgl_kirim">
        <InsertItemTemplate>
             <uc1:DateInput ID="txbkirim" runat="server" Text_Width="0" Text='<%#Bind("tgl_kirim") %>' TextMode="SingleLine" CssClass="form-control"></uc1:DateInput>
        </InsertItemTemplate>
   </asp:TemplateField>

Code behind:

AjaxControlToolkit.CalendarExtender calender = (AjaxControlToolkit.CalendarExtender)DetailsView3.FindControl("txbkirim");
calender.SelectedDate = DateTime.Now.Date;

Why it's not work?

I want to access id("cal1") from ASCX page, how to do that?

Gusti Arya
  • 1,145
  • 2
  • 12
  • 29
Rahmat
  • 107
  • 8
  • `txbkirim` is id of user control instance, not the calendar instance. You first need to cast `DetailsView3.FindControl("txbkirim");` to user control and then do another FindControl by calendar id `cal1` from the user control. – Chetan Ranpariya Dec 11 '17 at 03:31
  • `DateInput di = (DateInput)DetailsView3.FindControl("txbkirim"); AjaxControlToolkit.CalendarExtender cal = AjaxControlToolkit.CalendarExtender)di .FindControl("cal1");` – Chetan Ranpariya Dec 11 '17 at 03:33
  • not work , after i try like that i write code "di.SelectedDate = Datime.Now.Date " SelectedDate is not show? – Rahmat Dec 11 '17 at 03:38
  • You should do `cal.SelectedDate` – Chetan Ranpariya Dec 11 '17 at 03:41
  • Object reference not set to an instance of an object. not work , findcontrol("cal1"); id "cal1" in ascx not aspx – Rahmat Dec 11 '17 at 04:03
  • Can you update the post with latest code you are trying and tell which line is causing the exception? – Chetan Ranpariya Dec 11 '17 at 04:06
  • Did you read this https://stackoverflow.com/questions/881416/finding-user-control-in-templatefield-of-detailsview – Chetan Ranpariya Dec 11 '17 at 04:07

0 Answers0