user control properties not available

N

nic

I have a user control with properties exposed as:

Public Scorecard As Integer, _
Store As Integer, _
MonthNo As Integer, _
YearNo As Integer

I can set these properties from the calling page and can response.write
these values within the user control. BUT! I cannot access these values
within functions that I have on the page. I have tried using the property
set/get syntax and seperate private variables as well, but it makes no
difference. What am I missing here?

Thanks
nick

Here is the user control code:

<%@ Control Language="VB" debug="true" %>
<%@ import Namespace="System.Configuration" %>
<%@ import Namespace="Microsoft.ApplicationBlocks.Data" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.SqlClient" %>

<script runat="server">

Private strConn As string =
ConfigurationSettings.AppSettings("MM_CONNECTION_STRING_cnBSC")
Private intPerspective As Integer

'Exposed properties
Public Scorecard As Integer, _
Store As Integer, _
MonthNo As Integer, _
YearNo As Integer

Private Sub GetParentHeaders()
rptPerspectives.DataSource = SqlHelper.ExecuteReader(strConn,
"dbo.spGetAllPerspectives")
rptPerspectives.DataBind()
End Sub

Private Function GetChildLinks(ByVal intPer as Integer) As SqlDataReader
Return SqlHelper.ExecuteReader(strConn,
"dbo.spGetMeasurePerformanceForPerspective", Scorecard, intPer, Store,
MonthNo, YearNo)
End Function

Private Sub Page_Load(Src As Object, E As EventArgs)
GetParentHeaders()
End Sub

</script>
<table width="100%" border="0" cellspacing="0" cellpadding="0" border="0"
id="tblRepeaterData">
<asp:repeater id="rptPerspectives" runat="server" >
<ItemTemplate>
<tr>
<td colspan="10" bgcolor="#999999"><h2><%#
DataBinder.Eval(Container.DataItem, "per_name") %></h2></td>
</tr>
<tr>
<td rowspan="2"><h3>Objective</h3></td>
<td rowspan="2" class="style1"><h3>Measure</h3></td>
<td rowspan="2" class="style1"><h3>Weighting</h3></td>
<td colspan="3"><div align="center">
<h3>Target</h3>
</div></td>
<td rowspan="2" class="style1"><h3>Score</h3></td>
<td rowspan="2" class="style1"><h3>Prev</h3></td>
<td rowspan="2"><h3>% Change </h3></td>
<td rowspan="2" class="style1">&nbsp;</td>
</tr>
<tr>
<td><div align="center">
<h3>6m</h3>
</div></td>
<td><div align="center">
<h3>1y</h3>
</div></td>
<td><div align="center">
<h3>3y</h3>
</div></td>
</tr>
<%
Response.Write("Scorecard=" & Scorecard)
Response.Write("<br>Store=" & Store)
Response.Write("<br>MonthNo=" & MonthNo)
Response.Write("<br>YearNo=" & YearNo)
%>
<asp:repeater id="rptScores" runat="server" DataSource='<%#
GetChildLinks(CType(DataBinder.Eval(Container.DataItem, "per_id"),Integer))
%>'>
<ItemTemplate>
<tr>
<td class="style3"><%# DataBinder.Eval(Container.DataItem,
"ob_name") %></td>
<td class="style3"><%# DataBinder.Eval(Container.DataItem,
"mes_name") %></td>
<td class="style3"><%# DataBinder.Eval(Container.DataItem,
"mes_weighting") %>%</td>
<td class="style3"><%# DataBinder.Eval(Container.DataItem,
"mes_target_6m") %></td>
<td class="style3"><%# DataBinder.Eval(Container.DataItem,
"mes_target_1y") %></td>
<td class="style3"><%# DataBinder.Eval(Container.DataItem,
"mes_target_3y") %></td>
<td class="style3"><%# DataBinder.Eval(Container.DataItem,
"sp_score") %></td>
<td class="style3">&nbsp;</td>
<td class="style3">&nbsp;</td>
</tr>
</ItemTemplate>
</ASP:Repeater>
<tr>
<td colspan="10">&nbsp;</td>
</tr>
</ItemTemplate>
</asp:repeater>
</table>
 
K

Kelly Leahy

.... I meant I cannot access the values within functions

you need to declare the properties in the code-behind
file if you want to use them in the code-behind code.
This is because the actual UserControl that gets compiled
is a subclass of the code in the code-behind file,
generated automatically by the ASP.NET runtime compiler.

in other words, if you have have MyClass as the class in
your code behind file, the actual class that is used to
render the page "Inherits MyClass". This means that
stuff on the page (aspx file) has access (through
inheritance) to the stuff in the code-behind file, but
not vice versa.

The reason you can access controls on the aspx file is
that they are protected members of the code-behind class
that are actually set by the derived class generated by
ASP.NET.

Kelly
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top