Answered by:
Creating blog in asp.net with VB code

Question
-
User810354248 posted
I have tried a creating web blog for LAN.
Default.aspx for CS
<%@ Page Title="" Language="C#" MasterPageFile="~/master.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Default" %> <asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server"> <style type="text/css"> .style1 { text-align: left; } </style> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> <div> <div> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" class="gridview" ShowHeader="false" GridLines="None" style="font-family: Arial, Helvetica, sans-serif; font-size: small"> <Columns> <asp:TemplateField ShowHeader="false"> <ItemTemplate> <tr> <td> <div class="BlogHead"> <h2><a href='<%# Eval("Id", "details.aspx?Id={0}") %>' class="BlogHead"> <asp:Label ID="Label1" runat="server" Text='<%#Eval("Title") %>'></asp:Label></a></h2> </div> <div class="post_meta"> <span class="post_author blackLink nocursor"><asp:Label ID="Label2" runat="server" Text='<%#Eval("Author") %>'></asp:Label>,</span> <span class="date blackLink nocursor"><asp:Label ID="Label11" runat="server" Text='<%#Eval("BlogDate") %>'></asp:Label></span> </div> <br /> <div id="blbodythumb" style="text-align:justify;"> <p><asp:Label ID="Label100" runat="server" Text='<%#Eval("Content") %>' ></asp:Label></p></div><hr class="style-one" /> </td> </tr> </ItemTemplate> </asp:TemplateField> </Columns> <EmptyDataTemplate> No data </EmptyDataTemplate> </asp:GridView> </div> </div> </asp:Content>
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
Default.aspx
<%@ Page Title="" Language="VB" MasterPageFile="~/Master.master" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %> <asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server"> <style type="text/css"> .style1 { text-align: left; } </style> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> <div> <div> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" class="gridview" ShowHeader="false" GridLines="None" style="font-family: Arial, Helvetica, sans-serif; font-size: small"> <Columns> <asp:TemplateField ShowHeader="false"> <ItemTemplate> <tr> <td> <div class="BlogHead"> <h2><a href='<%# Eval("Id", "details.aspx?Id={0}") %>' class="BlogHead"> <asp:Label ID="Label1" runat="server" Text='<%#Eval("Title") %>'></asp:Label></a></h2> </div> <div class="post_meta"> <span class="post_author blackLink nocursor"><asp:Label ID="Label2" runat="server" Text='<%#Eval("Author") %>'></asp:Label>,</span> <span class="date blackLink nocursor"><asp:Label ID="Label11" runat="server" Text='<%#Eval("BlogDate") %>'></asp:Label></span> </div> <br /> <div id="blbodythumb" style="text-align:justify;"> <p><asp:Label ID="Label100" runat="server" Text='<%#Eval("Content") %>' ></asp:Label></p></div><hr class="style-one" /> </td> </tr> </ItemTemplate> </asp:TemplateField> </Columns> <EmptyDataTemplate> No data </EmptyDataTemplate> </asp:GridView> </div> </div> </asp:Content>
please guide me
Sunday, November 13, 2016 9:03 AM
Answers
-
User283571144 posted
Hi Baiju EP,
Baiju EP
Default.aspx.CS Code is as under which works fine. Then i converted my blog to VB then VB code is not workingAccording 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:
<asp:TextBox ID="txtCounter" runat="server"></asp:TextBox> <asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClientClick="return CheckIsRepeat();" OnClick="btnSubmit_Click" /> <hr/> Button Click event:<asp:Label ID="Label1" runat="server" Text=" "></asp:Label> <br/> Page load event:<asp:Label ID="Label2" runat="server" Text=""></asp:Label> </div>
Code-behind:
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
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, November 14, 2016 6:20 AM
All replies
-
User475983607 posted
I have tried a creating web blog for LAN.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.
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.
please guide meKeep 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.
Sunday, November 13, 2016 12:51 PM -
User810354248 posted
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.
Monday, November 14, 2016 2:43 AM -
User283571144 posted
Hi Baiju EP,
Baiju EP
Default.aspx.CS Code is as under which works fine. Then i converted my blog to VB then VB code is not workingAccording 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:
<asp:TextBox ID="txtCounter" runat="server"></asp:TextBox> <asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClientClick="return CheckIsRepeat();" OnClick="btnSubmit_Click" /> <hr/> Button Click event:<asp:Label ID="Label1" runat="server" Text=" "></asp:Label> <br/> Page load event:<asp:Label ID="Label2" runat="server" Text=""></asp:Label> </div>
Code-behind:
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
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, November 14, 2016 6:20 AM