[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.aspnet.mobile

How to access a control in a Panel / DeviceSpecific / ContentTemplate ?

(Craig)

2/26/2002 9:01:00 PM

I have the following device-specific code:

<mobile:Panel id="Panel1" runat="server">
<mobile:DeviceSpecific id="DeviceSpecific1" runat="server">
<Choice xmlns="Mobile HTML3.2 Template" Filter="isHTML32">
<ContentTemplate>
<br/>
<table>
<tr>
<td>
<mobile:Label id="lblExpDate" runat="server" Text="Exp
Date:" />
</td>
<td>
<mobile:Label id="expirationDate" Text=""
runat="server" BreakAfter="false" /><mobile:Command
id="cmdExpirationDate" Text="..." OnClick="cmdExpDate_Click"
runat="server" />
</td>
</tr>
</table>
</ContentTemplate>
</Choice>
</mobile:DeviceSpecific>
</mobile:Panel>

Then, I have the mobile:calendar control in another mobile:form on my
page, that when the user selects the date, I want the label
'expirationDate' to display the selected date. Everything works fine,
the form displays, the user clicks a button, is sent to the calendar
form, selects a date, but when I try to set the 'expirationDate' Text
on the mobile:form above, I can't get it to work. I've tried using
FindControl(...) to access the Label, but I always get Nothing in
return. I assume I am not understanding what hierarchy I have to go
through to get to the control/Label. How do I access the
'expirationDate' Label so I can change its .Text = "some date"? (VB,
please!)

Thanks!
Craig
2 Answers

Craig Deelsnyder

2/26/2002 9:40:00 PM

0

Ah, yes, ask question after many hours of searching, then end up answering
own question:

myLabel =
CType(Panel1.Controls(0).FindControl("expirationDate"),System.Web.UI.MobileC
ontrols.Label)

TemplateContainer is not accessible by name, hence the '0' argument. If
that's not acceptable, you have to iterate through the controls and blindly
try/catch:

http://groups.google.com/groups?hl=en&threadm=fYzVopgpBHA.1752%40c...
7&rnum=1&prev=/groups%3Fq%3Dgroup%253Amicrosoft.public.dotnet.framework.aspn
et.mobile%2Bcontenttemplate%26hl%3Den

Craig


"Craig" <cdeelsny@yahoo.com> wrote in message
news:d9e880a6.0202261130.2ab13cf9@posting.google.com...
> I have the following device-specific code:
>
> <mobile:Panel id="Panel1" runat="server">
> <mobile:DeviceSpecific id="DeviceSpecific1" runat="server">
> <Choice xmlns="Mobile HTML3.2 Template" Filter="isHTML32">
> <ContentTemplate>
> <br/>
> <table>
> <tr>
> <td>
> <mobile:Label id="lblExpDate" runat="server" Text="Exp
> Date:" />
> </td>
> <td>
> <mobile:Label id="expirationDate" Text=""
> runat="server" BreakAfter="false" /><mobile:Command
> id="cmdExpirationDate" Text="..." OnClick="cmdExpDate_Click"
> runat="server" />
> </td>
> </tr>
> </table>
> </ContentTemplate>
> </Choice>
> </mobile:DeviceSpecific>
> </mobile:Panel>
>
> Then, I have the mobile:calendar control in another mobile:form on my
> page, that when the user selects the date, I want the label
> 'expirationDate' to display the selected date. Everything works fine,
> the form displays, the user clicks a button, is sent to the calendar
> form, selects a date, but when I try to set the 'expirationDate' Text
> on the mobile:form above, I can't get it to work. I've tried using
> FindControl(...) to access the Label, but I always get Nothing in
> return. I assume I am not understanding what hierarchy I have to go
> through to get to the control/Label. How do I access the
> 'expirationDate' Label so I can change its .Text = "some date"? (VB,
> please!)
>
> Thanks!
> Craig


Shanku Niyogi

2/28/2002 1:03:00 AM

0

Craig,

In RTM (and I believe Beta 2), Panel also has a property named Content (as
well as properties named Header and Footer) that will give you the template
container you want, so that you don't have to search by index. Be sure to
check for null - this lets you handle situations where you don't use a
template at all.


Shanku





--
This posting is provided "AS IS" with no warranties, and confers no rights.