Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Web Controls / July 2006

Tip: Looking for answers? Try searching our database.

Set property in user control

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
stan - 31 Jul 2006 11:27 GMT
I have a user control where I defined a boolean property. I cannot set the
property in the code behind - the control is part of the Datagrid.  I tried
to pass the property the following way:
<aaa:MyControl runat="server" id="stan" IsReady="<%# booleanReady %>"/>
However, that does not work.  It looks like the "set" for the property does
not get executed.  However, it works if I hardcode "true" or "false".  I am
using .Net 1.1, VB. Can someone help?

TIA,
Stan
Alessandro Zifiglio - 31 Jul 2006 15:55 GMT
hi Stan, i think what you are missing is the call to your pages DataBind
method. Call this method versus only calling your DataGrids databind method.
The following test works and i dont see why it shouldnt work for you.
eg.

Dim booleanReady As Boolean = True
   Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs)
       if (not ispostback) then
       DataGrid1.DataSource = CreateDataSource() ' to your datasource
       ' Note that following line is commented out
       'DataGrid1.DataBind()
       Me.DataBind()
       end if
   End Sub

Regards,
Alessandro Zifiglio
http://www.AsyncUI.net

>I have a user control where I defined a boolean property. I cannot set the
> property in the code behind - the control is part of the Datagrid.  I
[quoted text clipped - 9 lines]
> TIA,
> Stan
Alessandro Zifiglio - 31 Jul 2006 16:00 GMT
Stan, following is the come code i used to test under asp.net 1.1 :
Regards,
Alessandro Zifiglio
http://www.AsyncUI.net

Containing page .aspx :
<%@ Page Language="VB"%>
<html>
<head id="Head1">
 <title>Untitled Page</title>
 <script runat="server">
   Dim booleanReady As Boolean = True
   Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs)
       DataGrid1.DataSource = CreateDataSource()
       'DataGrid1.DataBind()
       Me.DataBind()
   End Sub
   Function CreateDataSource() As ICollection

        ' Create sample data for the DataList control.
        Dim dt As DataTable = New DataTable()
        Dim dr As DataRow

        ' Define the columns of the table.
        dt.Columns.Add(New DataColumn("BoolValue", GetType(Boolean)))

        ' Populate the table with sample values.
       dr = dt.NewRow()
 dr(0) = true
 dt.Rows.Add(dr)

 dr = dt.NewRow()
 dr(0) = false
 dt.Rows.Add(dr)

 dr = dt.NewRow()
 dr(0) = true
 dt.Rows.Add(dr)

        Dim dv As DataView = New DataView(dt)
        Return dv

     End Function

 </script>
</head>
<body>
 <form id="form1" runat="server">
  <div>
   <asp:DataGrid id="DataGrid1" runat="server">
   <Columns>
   <asp:TemplateColumn HeaderText="booleanReady">
   <ItemTemplate>
   <uc1:WebUserControlTest id="WebUserControlTest1" IsReady='<%#
booleanReady %>' runat="server">
   </uc1:WebUserControlTest>
   </ItemTemplate>
   </asp:TemplateColumn>
   </Columns>
   </asp:DataGrid>
  </div>
 </form>
</body>
</html>

your user control .ascx :
------------------------------
<%@ Control Language="VB"%>
<script runat="server">
   Private isReadyValue As Boolean = False
   Public Property IsReady() As Boolean
       Get
           Return isReadyValue
       End Get
       Set(ByVal value As Boolean)
           isReadyValue = value
       End Set
   End Property

   Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs)
           Label1.Text = IsReady.ToString()
   End Sub
</script>
<asp:Label id="Label1" runat="server"></asp:Label>
> hi Stan, i think what you are missing is the call to your pages DataBind
> method. Call this method versus only calling your DataGrids databind
[quoted text clipped - 30 lines]
>> TIA,
>> Stan
Stan - 31 Jul 2006 17:35 GMT
Allessandro,
       this is alomost the same thing I do.  All works if the variable is
assigned a value that does not change.  However, I set the value based on
a condition.  it happens just before the bind.  It looks like the "set"
is bypassed.  I do the debug statement inside the "set" - it works only
when the value is hardcoded or defined in the code and not changed.

Stan

> Stan, following is the come code i used to test under asp.net 1.1 :
> Regards,
[quoted text clipped - 117 lines]
>>> TIA,
>>> Stan
Stan - 31 Jul 2006 21:52 GMT
Never mind.  Thanks for your help.  I figured it out.  User error.
Stan

> Allessandro,
>          this is alomost the same thing I do.  All works if the
[quoted text clipped - 129 lines]
>>>> TIA,
>>>> Stan
Alessandro Zifiglio - 31 Jul 2006 21:58 GMT
your welcome stan,

Regards,
Alessandro Zifiglio
http://www.AsyncUI.net

> Never mind.  Thanks for your help.  I figured it out.  User error.
> Stan
[quoted text clipped - 132 lines]
>>>>> TIA,
>>>>> Stan

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.