难倒使用自定义属性的用户控件 [英] Stumped With Custom Property on User Control

查看:111
本文介绍了难倒使用自定义属性的用户控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个ASP.NET用户控件。当我明确地提供了一个自定义属性的值,该值传递给控制。然而,当我尝试从一个数据源使用的值,该值不会传递到控制。

I have created an ASP.NET usercontrol. When I explicity provide the value for a custom property, the value is passed to the control. However, when I try to use the value from a datasource, the value is not passed to the control.

用户控件位于一个FormView内。 FormView控件成功地显示基础记录。我试图传递给控制值从FormView的数据源中的列。这适用

The user control sits within a FormView. The FormView successfully displays the underlying record. I am attempting to pass to the control a value in a column from the FormView's datasource. This works

<asp:formview .... />
<editTemplate>
<uctrl:DateSelector ID="DateSelector1" runat="server" DateValue="5/30/2011" /><br /> 
<%#Eval("MilestoneDate")%>    
</editTemplate>
</asp:formview>

这不...

<asp:formview .... />
<editTemplate>
<uctrl:DateSelector ID="DateSelector1" runat="server" DateValue='<%#Eval("MilestoneDate")%>' /><br /> 
<%#Eval("MilestoneDate")%>   
</editTemplate>
</asp:formview>

我已经证实,MileStoneDate确实有在它的一个值。无论出于何种原因,该值不被传递到控制,但控制不认识一个字面值。

I have confirmed that MileStoneDate does have a value in it. For whatever the reason, the value is not being passed to the control, however the control does recognize a literal value.

Imports Microsoft.VisualBasic 
Imports System.Data 
Imports System.Data.SqlClient 
Imports System.Web.UI 
Imports System.ComponentModel 

Partial Class content_WebUserControl 
    Inherits System.Web.UI.UserControl 
    <Bindable(True, BindingDirection.OneWay)> 
    Public Property DateValue() As String 
        Get 
            Return _DateValue 
        End Get 
        Set(ByVal value As String) 
            _DateValue = value 
        End Set 
    End Property 
    Private _DateValue As String 
    Protected Sub Page_Load() Handles Me.Load 

        If IsDate(Me.DateValue) Then 
            Dim NewDate As DateTime = CDate(Me.DateValue) 
            LabelSelectedDateDisplay.Text = Me.DateValue 
            LabelSelectedDateDisplay_DayOfWeek.Text = NewDate.ToString("dddd") 
            TextBoxSelectedDate.Text = Me.DateValue 
        Else 
            LabelSelectedDateDisplay.Text = "" 
            LabelSelectedDateDisplay_DayOfWeek.Text = "" 
            TextBoxSelectedDate.Text = "" 
        End If 

    End Sub 


End Class

我在这个网址<一所指向的帖子href=\"http://stackoverflow.com/questions/2317089/asp-net-user-control-cant-initialize-a-user-control-property-using-eval\">ASP.NET用户控制:无法初始化使用eval用户控件属性(&QUOT; ...&QUOT;)

不过,根据我的职位的理解,我应该怎样工作。

However, based on my understanding of the post, what I have should be working.

推荐答案

它看起来像问题可能是时间/事件相关。

It looks like the issue might be timing/event related.

当您设定℃的财产;%#%&GT; ,该值被分配到控件的数据绑定事件中的财产。如果您在的Page_Load()时间寻找它,它不会是那里。

When you set a property with <%# %>, the value is assigned to the property during the Control's databinding event. If you look for it at Page_Load() time, it won't be there yet.

如果你改变code,检查在 preRender 事件中的价值,它应该在那里。

If you change your code to check the value in the PreRender event, it should be there.

这篇关于难倒使用自定义属性的用户控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆