locked
DeviceSpecific control not working... why??? RRS feed

  • Question

  • User1989204087 posted
    Hi,
    I am developing a Mobile web in which I try to use <DeviceSpecific> tags to format the result I get from a database such as this:
      
    <mobile:DeviceSpecific id=d Runat="server"><CHOICE Xmlns="http://schemas.microsoft.com/mobile/html32template" Filter="isHTML32"><HEADERTEMPLATE><?xml:namespace prefix = asp /><asp:Table id=tbl Runat="server"><asp:TableRow id=r1 Runat="server"><asp:TableCell id=c1 Runat="server"><?xml:namespace prefix = mobile /><mobile:TextView id=TVStory runat="server"></mobile:TextView></asp:TableCell></asp:TableRow><asp:TableRow id=Tablerow1 Runat="server"><asp:TableCell id=Tablecell1 Runat="server"><mobile:TextView id=Textview1 runat="server"></mobile:TextView></asp:TableCell></asp:TableRow></asp:Table></HEADERTEMPLATE></CHOICE></mobile:DeviceSpecific><mobile:DeviceSpecific id=d Runat="server"><CHOICE Xmlns="http://schemas.microsoft.com/mobile/html32template" Filter="isHTML32"><HEADERTEMPLATE><asp:Table id=tbl Runat="server"><asp:TableRow id=r1 Runat="server"><asp:TableCell id=c1 Runat="server"><mobile:TextView id=TVStory runat="server"></mobile:TextView></asp:TableCell></asp:TableRow><asp:TableRow id=Tablerow1 Runat="server"><asp:TableCell id=Tablecell1 Runat="server"><mobile:TextView id=Textview1 runat="server"></mobile:TextView></asp:TableCell></asp:TableRow></asp:Table></HEADERTEMPLATE></CHOICE></mobile:DeviceSpecific>1. The TextView, TV1 and Label, Lb2 are handle in code such that :
        Tv1.text =  I will assign a 'result from a table"
         Lb2.text = I will assign a result from a table.

    If I do use the below deviceSpecifc , this will not work!!! There will be an error message like this:

    "Object reference not set to an instance of an object"

      <deviceSpecific id="d1" runat="server">
    <mobile:DeviceSpecific id=d Runat="server"><CHOICE Xmlns="http://schemas.microsoft.com/mobile/html32template" Filter="isHTML32"><HEADERTEMPLATE><asp:Table id=tbl Runat="server"><asp:TableRow id=r1 Runat="server"><asp:TableCell id=c1 Runat="server"><mobile:TextView id=TVStory runat="server"></mobile:TextView></asp:TableCell></asp:TableRow><asp:TableRow id=Tablerow1 Runat="server"><asp:TableCell id=Tablecell1 Runat="server"><mobile:TextView id=Textview1 runat="server"></mobile:TextView></asp:TableCell></asp:TableRow></asp:Table></HEADERTEMPLATE></CHOICE></mobile:DeviceSpecific><mobile:DeviceSpecific id=d Runat="server"><CHOICE Xmlns="http://schemas.microsoft.com/mobile/html32template" Filter="isHTML32"><HEADERTEMPLATE><asp:Table id=tbl Runat="server"><asp:TableRow id=r1 Runat="server"><asp:TableCell id=c1 Runat="server"><mobile:TextView id=TVStory runat="server"></mobile:TextView></asp:TableCell></asp:TableRow><asp:TableRow id=Tablerow1 Runat="server"><asp:TableCell id=Tablecell1 Runat="server"><mobile:TextView id=Textview1 runat="server">  <choice filter="IsHtml32">
       <Headertemplate>
               <asp:table id="t1" runat="server">
                  <asp:tableRow id="r1" runat="server">
                      <asp:tablecell id="c1" runat="server">
                           <mobile:TextView id="Tv1" runat="server"></mobile:TextView>
                       </asp:tablCell>
                     </asp:tableRow>

                    <asp:tableRow id="r2" runat="server">
                      <asp:tablecell id="c2" runat="server">
                           <mobile:Label  id="Lb2" runat="server"></mobile:Label>
                       </asp:tablCell>
                     </asp:tableRow>
              </asp:table>
           </Headertemplate>
       </choice>
    </deviceSpecifi>

    However, If I dont assign values to Tv1 and Lb2 and put some text in them, this will work! WHy??

    <asp:table id="t1" runat="server">
                  <asp:tableRow id="r1" runat="server">
                      <asp:tablecell id="c1" runat="server">
                           <mobile:TextView id="Tv1" runat="server">This will work</mobile:TextView>
                       </asp:tablCell>
                     </asp:tableRow>

                    <asp:tableRow id="r2" runat="server">
                      <asp:tablecell id="c2" runat="server">
                           <mobile:Label  id="Lb2" runat="server">Here, too!</mobile:Label>
                       </asp:tablCell>
                     </asp:tableRow>
              </asp:table>

    can someone help, please....
       </mobile:TextView></asp:TableCell></asp:TableRow></asp:Table></HEADERTEMPLATE></CHOICE></mobile:DeviceSpecific>
    Wednesday, June 22, 2005 1:19 AM

All replies

  • User286710293 posted
    My English is very poor
    if in your web.config file  not "IsHtml32" then you code is error!
     notice:IsHtml32  and   isHTML32
    ____________________________________________________________________________
    <mobile:Form id="Form1" runat="server">
      <mobile:DeviceSpecific id="DeviceSpecific1" runat="server">
       <Choice Filter="isHTML32" Xmlns="http://schemas.microsoft.com/mobile/html32template">
        <HeaderTemplate>
         <TABLE id="Table1" cellSpacing="1" cellPadding="1" width="300" border="0">
          <TR>
           <TD>
            <mobile:TextView id="tv1" runat="server">this is tv1</mobile:TextView></TD>
          </TR>
          <TR>
           <TD>
            <mobile:Label id="lb2" runat="server">this is lb2</mobile:Label></TD>
          </TR>
          <TR>
           <TD></TD>
          </TR>
         </TABLE>
        </HeaderTemplate>
       </Choice>
    ___________________________________________________________________________________
      </mobile:DeviceSpecific>
     </mobile:Form>
    Wednesday, June 22, 2005 4:59 AM
  • User-1361599924 posted
    Your code cannot get a reference to the controls as they are in the Device Specific template. You need to iterate through the control collection in order to get the reference to the control. This is similar to some code I wrote to find a custom control of mine;

    private void FindMyControl (Control container) {

    foreach (Control child in container.Controls)
    {
       if (myControl != null)
          return;

       if (child.GetType().Name == "blah_ascx")
       {
          myControl = (MyControl) child;
          return;
       }

       if (child.HasControls())
       {
          FindMyControl(child);
       }
    }

    }
    Wednesday, June 22, 2005 7:25 AM
  • User1989204087 posted
    Hi TrueLove,

    I checked the Web.config file, the spelling is correct : isHTML32.  This is the default file. Now, My questions are :

    1. Why there is error msg when TV1 and Lb2  are inside the <table>??
          
       In this case, I write server-side code to handle TV1 and Lb2 so that the result will be displayed in a table format. 

    2. why there is no error and work fine when I take out the TV1 and Lb2 OUT from the <table> and put them outside the <table>??

    so, this means the web.config file is OK.  the isHTML is also correct.


    3. BTW, is there ContentTemplate ?? I dont seems to find this anywhere!! There are only FooterTemplate and HeaderTemplate.

    please help....
    Wednesday, June 22, 2005 8:40 AM
  • User286710293 posted
    Why there is error msg when TV1 and Lb2  are inside the <table>??

    i not understand this!

    <mobile:Form id="Form2" runat="server">
      <mobile:DeviceSpecific id="DeviceSpecific1" runat="server">
       <CHOICE filter="isHTML32">
        <HEADERTEMPLATE>
         <asp:table id="t1" runat="server">
          <asp:tableRow id="r1">      'remove runat="server"
           <asp:TableCell ID="c1">   'remove ruant="server"
            <mobile:TextView id="Tv1" runat="server">textview</mobile:TextView>
           </asp:TableCell>
          </asp:tableRow>
          <asp:tableRow id="r2">
           <asp:TableCell id="c2">
            <mobile:Label id="Lb2" runat="server">label1</mobile:Label>
           </asp:TableCell>
          </asp:tableRow>
         </asp:table>
        </HEADERTEMPLATE>
       </CHOICE>
      </mobile:DeviceSpecific>
     </mobile:Form>

    code behind

     Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            If Not IsPostBack Then
            CType(Form2.Header.FindControl("tv1"), System.Web.UI.MobileControls.TextView).Text = "this is textview1"
            End If
        End Sub
    Wednesday, June 22, 2005 9:55 PM
  • User1989204087 posted
    Hi Truelove and GrudgeBoy,

    Grudgeboy:
    your suggested solution seems to be workable. Add all the controls into the Form.control container, this will allow them to be accessible in code. But How to do it in VB.net??? How to add all these control ??

    Hi TrueLove,

    assume the <table> is correctly declared.

    Your Ctype() function seems not working.  Yes, can use header to find the control, I convert it to the same type but it won't do.

    Ctype(form2.header.findcontrol("TV1"),System.Web.UI.MobileControls.TextView)

    is it I need to declare a Variable??
    Dim TVok as System.Web.UI.MobileControls.TextView = Ctype( .........), may this can??

    you mean, you find it first, then convert it to the type TextView. After this, I can manipulate it in Code Behind?

    I need to manipulate these control in Code Behind. I need to add the controls into form control container first, then I can manipulate these controls in Code Behind.

    please advise if you have tried it out...
    Thursday, June 23, 2005 5:18 AM
  • User286710293 posted

    Hi,SkySky
    my code all already tried!
    i insure the code is correct!
    Sorry,i not completeness understand you meaning!
    Please paste you all code!

    Thursday, June 23, 2005 9:36 PM
  • User1989204087 posted
    Hi Truelove,

    Thank, it is working now base on your Ctype().  I have these question:

    1.mobile control (TextView, Label) are already declared in Code Behind as well as inside the <table>  in html section. why there is no Text (for textview ) in TV1 when I run it??

    Work fine for TextView, textBox. Lable.

    2. When you have Command button declared in code Behind as well as inside <table>, how you handle this?
       if you use Ctype(), then how to use the event --Click?? if you put this command button outside the <table> and place it some where, the command button work when u click it.


    It seems we have to get reference for all the controls inside the <devicespecific>, so I try this method:

     I use controls.Add (control) , but it won't work.

    for each control in Device1
          Form2.Controls.Add( control)
    next

    ----- It seems only after you use Ctype(), then you can access the control in code. wonder why??? after all, all mobile controls already declared!!!-  anyway, it works now!!------



    10Q very much.
    Friday, June 24, 2005 3:20 AM
  • User286710293 posted

    1.mobile control (TextView, Label) are already declared in Code Behind as well as inside the <table>  in html section. why there is no Text (for textview ) in TV1 when I run it??

    i fell just the same paste you code fine!
    _____________________________________

    2、
    i don't know in this way may can!

     <asp:tablerow id="r3">
           <asp:TableCell>
            <asp:Button ID="button1" Runat="server" Text="button" OnClick="button_click" />   'notice:onclick
           </asp:TableCell>
          </asp:tablerow>

    Sub button_click(ByVal sender As Object, ByVal e As EventArgs)

            ActiveForm = Form1
            label0.text = "123"

        End Sub<asp:TableCell><asp:Button id=button1 onclick=button_click Text="button" Runat="server"></asp:Button></asp:TableCell>

    Saturday, June 25, 2005 10:29 AM