locked
ASP.Net Mobile Web Form to regular Web Form conversion help RRS feed

  • Question

  • User692369328 posted

    Hi all I have the following code in a mobile asp.net web form... My team decided that we drop the idea of using a mobile web form and go about a normal web form since most mobile devices support html nowadays and styling on a mobile web form is a hassle. how do i go about converting the following code to be compliant with a regular web form? Cheers guys




    <%@ Page Language="VB" Inherits="System.Web.UI.MobileControls.MobilePage" %>
    <%@ Register TagPrefix="mobile" Namespace="System.Web.UI.MobileControls" Assembly="System.Web.Mobile" %>
    <%@ Import Namespace ="system.data" %>
    
    
    <script runat="server">
        
        Sub bindtable(ByVal t As DataTable)
            
            SelectionList1.DataSource = t
            SelectionList1.DataTextField = "seats"
            SelectionList1.DataValueField = "seats"
            SelectionList1.DataBind()
            
            'SelectionList1.DataSource = t
            'SelectionList1.DataTextField = "A"
            'SelectionList1.DataValueField = "A"
            'SelectionList1.DataBind()
    
            'SelectionList2.DataSource = t
            'SelectionList2.DataTextField = "B"
            'SelectionList2.DataValueField = "B"
            'SelectionList2.DataBind()
    
            'SelectionList3.DataSource = t
            'SelectionList3.DataTextField = "C"
            'SelectionList3.DataValueField = "C"
            'SelectionList3.DataBind()
    
            'SelectionList4.DataSource = t
            'SelectionList4.DataTextField = "D"
            'SelectionList4.DataValueField = "D"
            'SelectionList4.DataBind()
    
        
        End Sub
        
         
        Sub createtable()
            
            Dim mytable As DataTable
            mytable = New DataTable
            
            'Dim aColumn As DataColumn
            'aColumn = New DataColumn
            'aColumn.ColumnName = "A"
            'mytable.Columns.Add(aColumn)
    
            'Dim bColumn As DataColumn
            'bColumn = New DataColumn
            'bColumn.ColumnName = "B"
            'mytable.Columns.Add(bColumn)
    
            'Dim cColumn As DataColumn
            'cColumn = New DataColumn
            'cColumn.ColumnName = "C"
            'mytable.Columns.Add(cColumn)
    
            'Dim dColumn As DataColumn
            'dColumn = New DataColumn
            'dColumn.ColumnName = "D"
            'mytable.Columns.Add(dColumn)
            
            Dim seats As DataColumn
            seats = New DataColumn
            seats.ColumnName = "seats"
            mytable.Columns.Add(seats)
            
            
            Dim r As DataRow
            
            For i = 1 To 10
                r = mytable.NewRow
                r("seats") = "A" & i
                mytable.Rows.Add(r)
            Next i
            
    
            For i = 1 To 10
                r = mytable.NewRow
                r("seats") = "B" & i
                mytable.Rows.Add(r)
            Next i
    
    
    
    
            For i = 1 To 10
                r = mytable.NewRow
                r("seats") = "C" & i
                mytable.Rows.Add(r)
            Next i
    
    
    
            For i = 1 To 10
                r = mytable.NewRow
                r("seats") = "D" & i
                mytable.Rows.Add(r)
            Next i
            
            Session("Table") = mytable
             
          
        End Sub
        
        
        
      
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
            
            If Not Page.IsPostBack Then
                
                createtable()
                bindtable(Session("Table"))
    
                
            End If
            
            Dim seatList As New ArrayList
            For i As Integer = 0 To SelectionList1.Items.Count - 1
                If SelectionList1.Items(i).Selected = True Then
                    seatList.Add(SelectionList1.Items(i).Text)
                    
                End If
            Next
            
            Session("bookedSeats") = seatList
            
        End Sub
        
        Protected Sub book_Click(ByVal sender As Object, ByVal e As System.EventArgs)
           
            
            
            Response.Redirect("summary.aspx")
            
        End Sub
    
        
        
      
    </script>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    
    <body>
        <mobile:form id="form1" runat="server">
        <mobile:SelectionList ID="SelectionList1"
                Runat="server" SelectType="CheckBox" >
            </mobile:SelectionList>
            
             <mobile:Command ID="book" Runat="server"
                OnClick="book_Click">Book Seats</mobile:Command>
        </mobile:form>
    </body>
    </html>
    




    <%@ Page Language="VB" Inherits="System.Web.UI.MobileControls.MobilePage" %>
    <%@ Register TagPrefix="mobile" Namespace="System.Web.UI.MobileControls" Assembly="System.Web.Mobile" %>
    <%@ Import Namespace ="system.data" %>


    <script runat="server">
        
        Sub bindtable(ByVal t As DataTable)
            
            SelectionList1.DataSource = t
            SelectionList1.DataTextField = "seats"
            SelectionList1.DataValueField = "seats"
            SelectionList1.DataBind()
            
            'SelectionList1.DataSource = t
            'SelectionList1.DataTextField = "A"
            'SelectionList1.DataValueField = "A"
            'SelectionList1.DataBind()

            'SelectionList2.DataSource = t
            'SelectionList2.DataTextField = "B"
            'SelectionList2.DataValueField = "B"
            'SelectionList2.DataBind()

            'SelectionList3.DataSource = t
            'SelectionList3.DataTextField = "C"
            'SelectionList3.DataValueField = "C"
            'SelectionList3.DataBind()

            'SelectionList4.DataSource = t
            'SelectionList4.DataTextField = "D"
            'SelectionList4.DataValueField = "D"
            'SelectionList4.DataBind()

        
        End Sub
        
         
        Sub createtable()
            
            Dim mytable As DataTable
            mytable = New DataTable
            
            'Dim aColumn As DataColumn
            'aColumn = New DataColumn
            'aColumn.ColumnName = "A"
            'mytable.Columns.Add(aColumn)

            'Dim bColumn As DataColumn
            'bColumn = New DataColumn
            'bColumn.ColumnName = "B"
            'mytable.Columns.Add(bColumn)

            'Dim cColumn As DataColumn
            'cColumn = New DataColumn
            'cColumn.ColumnName = "C"
            'mytable.Columns.Add(cColumn)

            'Dim dColumn As DataColumn
            'dColumn = New DataColumn
            'dColumn.ColumnName = "D"
            'mytable.Columns.Add(dColumn)
            
            Dim seats As DataColumn
            seats = New DataColumn
            seats.ColumnName = "seats"
            mytable.Columns.Add(seats)
            
            
            Dim r As DataRow
            
            For i = 1 To 10
                r = mytable.NewRow
                r("seats") = "A" & i
                mytable.Rows.Add(r)
            Next i
            

            For i = 1 To 10
                r = mytable.NewRow
                r("seats") = "B" & i
                mytable.Rows.Add(r)
            Next i




            For i = 1 To 10
                r = mytable.NewRow
                r("seats") = "C" & i
                mytable.Rows.Add(r)
            Next i



            For i = 1 To 10
                r = mytable.NewRow
                r("seats") = "D" & i
                mytable.Rows.Add(r)
            Next i
            
            Session("Table") = mytable
             
          
        End Sub
        
        
        
     
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
            
            If Not Page.IsPostBack Then
                
                createtable()
                bindtable(Session("Table"))

                
            End If
            
            Dim seatList As New ArrayList
            For i As Integer = 0 To SelectionList1.Items.Count - 1
                If SelectionList1.Items(i).Selected = True Then
                    seatList.Add(SelectionList1.Items(i).Text)
                    
                End If
            Next
            
            Session("bookedSeats") = seatList
            
        End Sub
        
        Protected Sub book_Click(ByVal sender As Object, ByVal e As System.EventArgs)
           
            
            
            Response.Redirect("summary.aspx")
            
        End Sub

        
        
     
    </script>

    <html xmlns="http://www.w3.org/1999/xhtml">

    <body>
        <mobile:form id="form1" runat="server">
        <mobile:SelectionList ID="SelectionList1"
                Runat="server" SelectType="CheckBox" >
            </mobile:SelectionList>
            
             <mobile:Command ID="book" Runat="server"
                OnClick="book_Click">Book Seats</mobile:Command>
        </mobile:form>
    </body>
    </html>

    Thursday, December 30, 2010 3:26 AM

Answers

  • User1943143334 posted

    Hi,

    <asp:DropDownList> cannot have checkboxes. You can use <asp:CheckBoxList> tag.

    Please check my C# Code:

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default4.aspx.cs" Inherits="Default4" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Untitled Page</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        <asp:CheckBoxList runat="server" ID="chkList">
        </asp:CheckBoxList>
        
        </div>
        </form>
    </body>
    </html>
    
    
     protected void Page_Load(object sender, EventArgs e)
        {
            DataTable mytable = new DataTable();
    
            DataColumn seats = new DataColumn();
    
            seats.ColumnName = "seats";
    
            mytable.Columns.Add(seats);
    
            DataRow dataRow = null;
    
            for (int i = 0; i < 10; i++)
            {
                dataRow = mytable.NewRow();
                dataRow[0] = "A" + i.ToString();
                mytable.Rows.Add(dataRow);
            }
    
    
            chkList.DataSource = mytable;
            chkList.DataTextField = "seats";
            chkList.DataValueField = "seats";
            chkList.DataBind();
    
    
        }
    


     

    The above code is working fine for me.

    Convert it to VB code.

    Hope it helps u...

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, January 1, 2011 2:57 AM

All replies

  • User1943143334 posted

    Hi,

    You can use general Web server controls.

    In the above example you can use,

    <form> instead of <mobile:form>

    <asp:DropDownList>instead of <mobile:SelectionList>

    <asp:Button>instead of <mobile:command>

    etc., etc.,

    Check the following links for more information on Mobile web development,

    http://roopeshreddy.wordpress.com/2010/07/25/mobile-development-in-asp-net/

    http://roopeshreddy.wordpress.com/2010/09/23/latest-browser-configuration-files/

    http://roopeshreddy.wordpress.com/2010/10/25/developing-web-applications-for-blackberry-mobiles-using-microsoft-asp-net/

    Check the Mobile Browser detection API,

    http://51degrees.codeplex.com/

    Hope it helps u... 

    Thursday, December 30, 2010 8:54 AM
  • User692369328 posted

    Hi thanks for the reply! Well I did change the tags.. even from the selectionlist to a checkboxlist however i am not able to retrieve the dataset as declared above. Note I converted all the necessary tags i.e mobile web form to web form, command to button

    Thursday, December 30, 2010 10:52 AM
  • User1943143334 posted

    Hi,

    You want to display list of checkboxes or  dropdown list with the options?

    If you want dropdownlist(Select tag in HTML) then u have to use <asp:DropDownList> tag.

    Let me know, if ur problem solved with the above solution.

     

    Hope it helps u...

    Thursday, December 30, 2010 10:25 PM
  • User692369328 posted


    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default2.aspx.vb" Inherits="Default2" %> <%@ Import Namespace ="system.data" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> Sub bindtable(ByVal t As DataTable) SelectionList1.DataSource = t SelectionList1.DataTextField = "seats" SelectionList1.DataValueField = "seats" SelectionList1.DataBind() 'SelectionList1.DataSource = t 'SelectionList1.DataTextField = "A" 'SelectionList1.DataValueField = "A" 'SelectionList1.DataBind() 'SelectionList2.DataSource = t 'SelectionList2.DataTextField = "B" 'SelectionList2.DataValueField = "B" 'SelectionList2.DataBind() 'SelectionList3.DataSource = t 'SelectionList3.DataTextField = "C" 'SelectionList3.DataValueField = "C" 'SelectionList3.DataBind() 'SelectionList4.DataSource = t 'SelectionList4.DataTextField = "D" 'SelectionList4.DataValueField = "D" 'SelectionList4.DataBind() End Sub Sub createtable() Dim mytable As DataTable mytable = New DataTable 'Dim aColumn As DataColumn 'aColumn = New DataColumn 'aColumn.ColumnName = "A" 'mytable.Columns.Add(aColumn) 'Dim bColumn As DataColumn 'bColumn = New DataColumn 'bColumn.ColumnName = "B" 'mytable.Columns.Add(bColumn) 'Dim cColumn As DataColumn 'cColumn = New DataColumn 'cColumn.ColumnName = "C" 'mytable.Columns.Add(cColumn) 'Dim dColumn As DataColumn 'dColumn = New DataColumn 'dColumn.ColumnName = "D" 'mytable.Columns.Add(dColumn) Dim seats As DataColumn seats = New DataColumn seats.ColumnName = "seats" mytable.Columns.Add(seats) Dim r As DataRow Dim i As Integer For i = 1 To 10 r = mytable.NewRow r("seats") = "A" & i mytable.Rows.Add(r) Next i For i = 1 To 10 r = mytable.NewRow r("seats") = "B" & i mytable.Rows.Add(r) Next i For i = 1 To 10 r = mytable.NewRow r("seats") = "C" & i mytable.Rows.Add(r) Next i For i = 1 To 10 r = mytable.NewRow r("seats") = "D" & i mytable.Rows.Add(r) Next i Session("Table") = mytable End Sub Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) If Not Page.IsPostBack Then createtable() bindtable(Session("Table")) End If Dim seatList As New ArrayList For i As Integer = 0 To SelectionList1.Items.Count - 1 If SelectionList1.Items(i).Selected = True Then seatList.Add(SelectionList1.Items(i).Text) End If Next Session("bookedSeats") = seatList End Sub Protected Sub book_Click(ByVal sender As Object, ByVal e As System.EventArgs) Response.Redirect("summary.aspx") End Sub </script> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <asp:DropDownList ID="selectionlist1" runat="server"> </asp:DropDownList> </div> </form> </body> </html>




    I modified the code in such that it is a normal asp.net web form. however the output of my data list dosent appear. Is the logic of the code right?


    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default2.aspx.vb" Inherits="Default2" %>
    <%@ Import Namespace ="system.data" %>


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <script runat="server">
        Sub bindtable(ByVal t As DataTable)
            
            SelectionList1.DataSource = t
            SelectionList1.DataTextField = "seats"
            SelectionList1.DataValueField = "seats"
            SelectionList1.DataBind()
            
            'SelectionList1.DataSource = t
            'SelectionList1.DataTextField = "A"
            'SelectionList1.DataValueField = "A"
            'SelectionList1.DataBind()

            'SelectionList2.DataSource = t
            'SelectionList2.DataTextField = "B"
            'SelectionList2.DataValueField = "B"
            'SelectionList2.DataBind()

            'SelectionList3.DataSource = t
            'SelectionList3.DataTextField = "C"
            'SelectionList3.DataValueField = "C"
            'SelectionList3.DataBind()

            'SelectionList4.DataSource = t
            'SelectionList4.DataTextField = "D"
            'SelectionList4.DataValueField = "D"
            'SelectionList4.DataBind()

        
        End Sub
        
         
        Sub createtable()
            
            Dim mytable As DataTable
            mytable = New DataTable
            
            'Dim aColumn As DataColumn
            'aColumn = New DataColumn
            'aColumn.ColumnName = "A"
            'mytable.Columns.Add(aColumn)

            'Dim bColumn As DataColumn
            'bColumn = New DataColumn
            'bColumn.ColumnName = "B"
            'mytable.Columns.Add(bColumn)

            'Dim cColumn As DataColumn
            'cColumn = New DataColumn
            'cColumn.ColumnName = "C"
            'mytable.Columns.Add(cColumn)

            'Dim dColumn As DataColumn
            'dColumn = New DataColumn
            'dColumn.ColumnName = "D"
            'mytable.Columns.Add(dColumn)
            
            Dim seats As DataColumn
            seats = New DataColumn
            seats.ColumnName = "seats"
            mytable.Columns.Add(seats)
            
            
            Dim r As DataRow
            Dim i As Integer
            
            For i = 1 To 10
                r = mytable.NewRow
                r("seats") = "A" & i
                mytable.Rows.Add(r)
            Next i
            

            For i = 1 To 10
                r = mytable.NewRow
                r("seats") = "B" & i
                mytable.Rows.Add(r)
            Next i




            For i = 1 To 10
                r = mytable.NewRow
                r("seats") = "C" & i
                mytable.Rows.Add(r)
            Next i



            For i = 1 To 10
                r = mytable.NewRow
                r("seats") = "D" & i
                mytable.Rows.Add(r)
            Next i
            
            Session("Table") = mytable
             
          
        End Sub
        
        
        
     
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
            
            If Not Page.IsPostBack Then
                
                createtable()
                bindtable(Session("Table"))

                
            End If
            
            Dim seatList As New ArrayList
            For i As Integer = 0 To SelectionList1.Items.Count - 1
                If SelectionList1.Items(i).Selected = True Then
                    seatList.Add(SelectionList1.Items(i).Text)
                    
                End If
            Next
            
            Session("bookedSeats") = seatList
            
        End Sub
        
        
        
        Protected Sub book_Click(ByVal sender As Object, ByVal e As System.EventArgs)
           
            
            
            Response.Redirect("summary.aspx")
            
        End Sub
    </script>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:DropDownList ID="selectionlist1" runat="server">
            </asp:DropDownList>
            
        </div>
        </form>
    </body>
    </html>

    Friday, December 31, 2010 1:52 AM
  • User1943143334 posted

    Hi,

    <asp:DropDownList> cannot have checkboxes. You can use <asp:CheckBoxList> tag.

    Please check my C# Code:

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default4.aspx.cs" Inherits="Default4" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Untitled Page</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        <asp:CheckBoxList runat="server" ID="chkList">
        </asp:CheckBoxList>
        
        </div>
        </form>
    </body>
    </html>
    
    
     protected void Page_Load(object sender, EventArgs e)
        {
            DataTable mytable = new DataTable();
    
            DataColumn seats = new DataColumn();
    
            seats.ColumnName = "seats";
    
            mytable.Columns.Add(seats);
    
            DataRow dataRow = null;
    
            for (int i = 0; i < 10; i++)
            {
                dataRow = mytable.NewRow();
                dataRow[0] = "A" + i.ToString();
                mytable.Rows.Add(dataRow);
            }
    
    
            chkList.DataSource = mytable;
            chkList.DataTextField = "seats";
            chkList.DataValueField = "seats";
            chkList.DataBind();
    
    
        }
    


     

    The above code is working fine for me.

    Convert it to VB code.

    Hope it helps u...

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, January 1, 2011 2:57 AM
  • User692369328 posted

    Hi I manage to convert it into VB.NEt Language and it works perfectly!!! Thank you very much :D

    And have a plesent year ahead!!!!

    Saturday, January 1, 2011 1:04 PM