I am new to programming, I have built a Desktop app in VB.Net that works perfectly, now I would like to convert it onto a Website, I know its not going to be easy but day one and it already seems to be a impossible task!!!
I am trying a simple task, trying to load DropDownList for Sql DataBase,the first part of my code works ok but second not, can anyone help please! Here is my code.
Oh the second dropdown needs to enter values from what ever is in first dropdown, if that makes sense.
Thanks
Imports System.Data.SqlClient
Imports System.Data
Partial Class Service_Manuals
Inherits System.Web.UI.Page
Dim SQLCon As New SqlConnection With {.ConnectionString = "Server=desktop-bi7l3hl\sqlexpress;Database=Cb_Radio_Data;User=sa;Pwd=keyn48"}
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
Dim SQLCmd As New SqlCommand("SELECT Manufacturer FROM Cb_Radios GROUP BY Manufacturer", SQLCon)
Dim SQLda As New SqlDataAdapter(SQLCmd)
Dim SQLdt As New DataTable()
SQLda.Fill(SQLdt)
DropDownList_Manu.DataTextField = "Manufacturer"
End Sub
Protected Sub DropDownList_Manu_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DropDownList_Manu.SelectedIndexChanged
Dim SQLCmd2 As New SqlCommand("SELECT Model FROM Cb_Radios WHERE Manufacturer = '" & DropDownList_Manu.Text & "'Group by Model", SQLCon)
Dim SQLda2 As New SqlDataAdapter(SQLCmd2)
Dim SQLdt2 As New DataTable()
SQLda2.Fill(SQLdt2)
DropDownList_Model.DataTextField = "Model"
DropDownList_Model.DataSource = SQLdt2
DropDownList_Model.DataBind()
End Sub
How a desktop app and a web site app is really different. The best you could do is that by isolating non UI related code so that it could be more easily reused but the whole UI part should be basically considered as a full rewrite.
Edit: in particular the HUGE difference is that the web is "stateless" ie unlike a desktop app where a form is created and stay in memory as long as the user is using it, for the web a new "form" is created for each web request. The purpose of this "form"
is to generate HTML markup that is sent back and rendered by the browser and at this step this server side "form" doesn"t exists any more (its only purpose is to render HTML markup to browser).
trying to load DropDownList for Sql DataBase,the first part of my code works ok but second not, can anyone help please!
You are loading the first dropdownlist with data on every postback so the selected value will get reset on each postback. Try loading data inside if not postback block like below
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If Not IsPostBack Then
Dim SQLCmd As New SqlCommand("SELECT Manufacturer FROM Cb_Radios GROUP BY Manufacturer", SQLCon)
Dim SQLda As New SqlDataAdapter(SQLCmd)
Dim SQLdt As New DataTable()
SQLda.Fill(SQLdt)
DropDownList_Manu.DataTextField = "Manufacturer"
DropDownList_Manu.DataSource = SQLdt
DropDownList_Manu.DataBind()
End If
End Sub
I hope the post made sense, DropDownList_Manu_SelectedIndexChange shows only Models that are from the Manufacturer I choose once I select a Manufacturer from list.
I sort of understand, with the little knowledge I have.
I am sat in front of both screens and making new UI to suit the code, and from I understand you are saying that there is very little memory so each time a user does a action it asks server again for the code. Is that right???
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Member
1 Points
4 Posts
How to convert Desktop app to Web app using VB.Net.
Jan 11, 2018 06:33 PM|keynaboutradios|LINK
Hi everyone!
I am new to programming, I have built a Desktop app in VB.Net that works perfectly, now I would like to convert it onto a Website, I know its not going to be easy but day one and it already seems to be a impossible task!!!
I am trying a simple task, trying to load DropDownList for Sql DataBase,the first part of my code works ok but second not, can anyone help please! Here is my code.
Oh the second dropdown needs to enter values from what ever is in first dropdown, if that makes sense.
Thanks
Imports System.Data.SqlClient
Imports System.Data
Partial Class Service_Manuals
Inherits System.Web.UI.Page
Dim SQLCon As New SqlConnection With {.ConnectionString = "Server=desktop-bi7l3hl\sqlexpress;Database=Cb_Radio_Data;User=sa;Pwd=keyn48"}
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
Dim SQLCmd As New SqlCommand("SELECT Manufacturer FROM Cb_Radios GROUP BY Manufacturer", SQLCon)
Dim SQLda As New SqlDataAdapter(SQLCmd)
Dim SQLdt As New DataTable()
SQLda.Fill(SQLdt)
DropDownList_Manu.DataTextField = "Manufacturer"
DropDownList_Manu.DataSource = SQLdt
DropDownList_Manu.DataBind()
End Sub
Protected Sub DropDownList_Manu_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DropDownList_Manu.SelectedIndexChanged
Dim SQLCmd2 As New SqlCommand("SELECT Model FROM Cb_Radios WHERE Manufacturer = '" & DropDownList_Manu.Text & "'Group by Model", SQLCon)
Dim SQLda2 As New SqlDataAdapter(SQLCmd2)
Dim SQLdt2 As New DataTable()
SQLda2.Fill(SQLdt2)
DropDownList_Model.DataTextField = "Model"
DropDownList_Model.DataSource = SQLdt2
DropDownList_Model.DataBind()
End Sub
All-Star
48280 Points
17983 Posts
Re: How to convert Desktop app to Web app using VB.Net.
Jan 11, 2018 06:39 PM|PatriceSc|LINK
Hi,
How a desktop app and a web site app is really different. The best you could do is that by isolating non UI related code so that it could be more easily reused but the whole UI part should be basically considered as a full rewrite.
Edit: in particular the HUGE difference is that the web is "stateless" ie unlike a desktop app where a form is created and stay in memory as long as the user is using it, for the web a new "form" is created for each web request. The purpose of this "form" is to generate HTML markup that is sent back and rendered by the browser and at this step this server side "form" doesn"t exists any more (its only purpose is to render HTML markup to browser).
How many forms to you have ?
All-Star
50831 Points
9895 Posts
Re: How to convert Desktop app to Web app using VB.Net.
Jan 11, 2018 06:43 PM|A2H|LINK
You are loading the first dropdownlist with data on every postback so the selected value will get reset on each postback. Try loading data inside if not postback block like below
Aje
My Blog | Dotnet Funda
Member
1 Points
4 Posts
Re: How to convert Desktop app to Web app using VB.Net.
Jan 11, 2018 06:56 PM|keynaboutradios|LINK
I have tried that and still not working!
I hope the post made sense, DropDownList_Manu_SelectedIndexChange shows only Models that are from the Manufacturer I choose once I select a Manufacturer from list.
Thanks
Member
1 Points
4 Posts
Re: How to convert Desktop app to Web app using VB.Net.
Jan 11, 2018 07:07 PM|keynaboutradios|LINK
Thanks
I sort of understand, with the little knowledge I have.
I am sat in front of both screens and making new UI to suit the code, and from I understand you are saying that there is very little memory so each time a user does a action it asks server again for the code. Is that right???
Star
8670 Points
2882 Posts
Re: How to convert Desktop app to Web app using VB.Net.
Jan 12, 2018 07:27 AM|Cathy Zou|LINK
Hi keynaboutradios
Yes, we will ask server again very time a post back occurs.
Your code seems to implement cascading dropdownlist.
So dropdownlist(DropDownList_Model ) shows only Models for Manufacture you choose from DropDownList_Manu list.
You will get better understanding and a good sample by referring to the links below:
https://www.aspsnippets.com/Articles/Creating-Cascading-DropDownLists-in-ASP.Net.aspx
Best regards
Cathy
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.