Default.aspx.CS Code is as under which works fine. Then i converted my blog to VB then VB code is not working
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
public partial class Default : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ourdb"].ConnectionString);
protected void Page_Load(object sender, EventArgs e)
{
BindBlog();
}
void BindBlog()
{
try
{
if (con.State == ConnectionState.Closed)
{
con.Open();
}
SqlCommand cmd = new SqlCommand("select * from BlogPost order by BlogDate desc ", con);
SqlDataAdapter adp = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
adp.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
cmd.Dispose();
}
catch (Exception k)
{
Response.Write(k.Message);
//throw;
}
finally
{
con.Close();
}
}
}
Default.aspx.VB code which is not working
Imports System.Collections.Generic
Imports System.Linq
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Data
Imports System.Data.SqlClient
Public Partial Class [Default]
Inherits System.Web.UI.Page
Private con As New SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("ourdb").ConnectionString)
Protected Sub Page_Load(sender As Object, e As EventArgs)
BindBlog()
End Sub
Private Sub BindBlog()
Try
If con.State = ConnectionState.Closed Then
con.Open()
End If
Dim cmd As New SqlCommand("select * from BlogPost order by BlogDate desc ", con)
Dim adp As New SqlDataAdapter(cmd)
Dim ds As New DataSet()
adp.Fill(ds)
GridView1.DataSource = ds
GridView1.DataBind()
cmd.Dispose()
Catch k As Exception
'throw;
Response.Write(k.Message)
Finally
con.Close()
End Try
End Sub
End Class
Can you clarify? This is a blog about a LAN or you actually placed the source files on a LAN? Keep in mind that web apps are hosted. Simply dropping .NET source files on a LAN does not magically create a web application.
Baiju EP
Default.aspx.CS Code is as under which works fine. Then i converted my blog to VB then VB code is not working
"Not working" is not very informative. What is not working? Are there errors and if so what are the errors? Does not working mean you are not getting the expected results? If so, what is your expected result and what actually happens.
Baiju EP
please guide me
Keep in mind that the way you have written the code, editing will be an issue because you are not using the the "If Page.IsPostBack" conversion.
I strongly suggest that you click the Learn link above and go through a few Web Forms tutorials to get an understanding of the basics.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Label2.Text = "Pageload executed"
End Sub
Protected Sub btnSubmit_Click(sender As Object, e As EventArgs)
Label1.Text = "Suceess"
End Sub
The result is:
Without Handles Me.Load result is:
So I suggest you could change your VB code as below:
public partial class Default : System.Web.UI.Page Handles Me.Load
{
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ourdb"].ConnectionString);
protected void Page_Load(object sender, EventArgs e)
{
BindBlog();
}
......
}
Best Regards,
Brando
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
Member
297 Points
1171 Posts
Creating blog in asp.net with VB code
Nov 13, 2016 09:03 AM|Baiju EP|LINK
I have tried a creating web blog for LAN.
Default.aspx for CS
Default.aspx.CS Code is as under which works fine. Then i converted my blog to VB then VB code is not working
Default.aspx.VB code which is not working
Default.aspx
please guide me
All-Star
52241 Points
23306 Posts
Re: Creating blog in asp.net with VB code
Nov 13, 2016 12:51 PM|mgebhard|LINK
Can you clarify? This is a blog about a LAN or you actually placed the source files on a LAN? Keep in mind that web apps are hosted. Simply dropping .NET source files on a LAN does not magically create a web application.
"Not working" is not very informative. What is not working? Are there errors and if so what are the errors? Does not working mean you are not getting the expected results? If so, what is your expected result and what actually happens.
Keep in mind that the way you have written the code, editing will be an issue because you are not using the the "If Page.IsPostBack" conversion.
I strongly suggest that you click the Learn link above and go through a few Web Forms tutorials to get an understanding of the basics.
https://www.asp.net/web-forms
Member
297 Points
1171 Posts
Re: Creating blog in asp.net with VB code
Nov 14, 2016 02:43 AM|Baiju EP|LINK
This blog is a part of an asp.net+VB web. and hosted in a web server which is not connected to internet. a small private network.
Star
9831 Points
3120 Posts
Re: Creating blog in asp.net with VB code
Nov 14, 2016 06:20 AM|Brando ZWZ|LINK
Hi Baiju EP,
According to your VB codes, I found you missed the "Handles Me.Load" keyword in the page load event.
If you missed the keyword, the vb.net aspx page will not executed the page load event's codes when page loaded.
Here is a small test:
ASXP:
Code-behind:
The result is:
Without Handles Me.Load result is:
So I suggest you could change your VB code as below:
public partial class Default : System.Web.UI.Page Handles Me.Load { SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ourdb"].ConnectionString); protected void Page_Load(object sender, EventArgs e) { BindBlog(); } ...... }
Best Regards,
Brando