1

I have developed usercontrol timePicker. I'm using Bootstrap and Ajaxtoolkit 4 but not using updatepanel

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="TimePicker.ascx.cs" Inherits="Controls_TimePicker" %>
    <script type="text/javascript">
        $(function () {
            $('#<%=divTime.ClientID %>').datetimepicker({
                /* language: 'ar-kw',*/
                language: 'en-US',
                maskInput: true,
                format: 'HH:mm PP',
                pickDate: false,
                pickSeconds: false,
                pick12HourFormat: true,
                pickTime: true,
                placement: 'left'
            });
        });
    </script>
    <div id="divTime" clientidmode="AutoID" runat="server" class="input-append date dropup">
        <span class="add-on "><i data-time-icon="icon-time" data-date-icon="icon-calendar"></i>
        </span>
        <asp:TextBox ID="txtDate" ClientIDMode="Predictable" Width="65%" type="text" runat="server"></asp:TextBox> 
    </div>

C#:

 public string Text
    {
        get { return txtDate.Text; }
        set { txtDate.Text = value; }
    }

By this property I can get Text Value from my webpage. It's working fine, but now I want to use Usercontrol (Timepicker) in repeater. Here is the code:

 protected void repeater_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
UserControl tmStart = (UserControl)e.Item.FindControl("tmStart");
Label lblStartTime = (Label)e.Item.FindControl("lblStartTime");
tmStart.Text = lblStart.Text;
     }

It's working fine outside repeater but in repeater it's not working, tmStart.Text (Text is giving error). Any idea what's wrong?

4

2 回答 2

0

我已经通过右键单击变量并单击快速信息解决了这个问题

这对我有用

 ((Controls_TimePicker)(tmStartEdit)).Text = lblStartTime.Text;
 ((Controls_TimePicker)tmEndEdit).Text = lblEndTime.Text;
 ((Controls_DatePickerAdmin)(cldrStartEdit)).Text = lblStartDate.Text;  
 ((Controls_DatePickerAdmin)(cldrEndEdit)).Text = lblEndDate.Text;

//Controls_TimePicker 显示为红色,但运行时没有给出错误,不知道为什么。

于 2013-05-27T15:14:41.720 回答
0

You should cast the tmStart control as the specific control, not the generic UserControl. The you will have access to the the Text Property.

protected void repeater_ItemCommand(object source, RepeaterCommandEventArgs e)
{
    Controls_TimePicker tmStart = (Controls_TimePicker)e.Item.FindControl("tmStart");
    Label lblStartTime = (Label)e.Item.FindControl("lblStartTime");
    tmStart.Text = lblStart.Text;
 }
于 2013-05-27T14:57:36.993 回答