开发者

ASP.NET User Control Value

I created a DatePicker user control (ASP code below, no code behind) which is simply a textbox, image button, and a sometimes visible calendar.

<%@ Control Language="vb" AutoEventWireup="false" _
    CodeBehind="myDatePicker.ascx.vb"
    Inherits="Website.myDate" %>

<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" _
    tagprefix="asp" %>

<asp:TextBox ID="Date1" runat="server"></asp:TextBox>
<asp:Image ID="Image1" runat="server" ImageUrl="~/Calendar_scheduleHS.png" />

<asp:CalendarExtender ID="Date1_CalendarExtender" runat="server" Enabled="True" 
    TargetControlID="Date1" PopupButtonID="Image1"  >
</asp:CalendarExtender>

Can I somehow tie or pass the value of the TextBox as the value of the whole control to use in the calling code?

EDIT: My actual goal here is to be able to tie the SelectedDate as a parameter of a database query. I was able to select values for the other parameters in a controls开发者_StackOverflow社区 dropdown list in a query parameter configuration window.


you would need to create on the code behind of your user control a property like this

Public ReadOnly Property SelectedDate() As String
        Get
            Dim format As String = "MM/dd/yyyy" 'Your format
            Dim _selectedDate As DateTime = DateTime.ParseExact(Date1.Text, format, CultureInfo.InvariantCulture)
            Return _selectedDate
        End Get
End Property


Are you saying you want to get the date from the CalendarExtender? If so, you can use the SelectedDate property on the CalendarExtender for that.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜