Very Simple question

S

SL

Could someone direct to a simple explanation of how to use MS Visual Studio
2003 to design .aspx code?
This code works if pasted into notepad and run as an .aspx file:

<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<script language="vb" runat="server">
Sub Page_Load(ByVal Sender As Object, ByVal E As EventArgs)
Dim objConnection As OleDBConnection
Dim objCommand As OleDBDataAdapter
Dim strConnect As String
Dim strCommand As String
Dim DataSet1 As New DataSet

strConnect = "Provider=Microsoft.Jet.OLEDB.4.0; "
strConnect += "Data Source =C:\Sample ASPNet\Ch02\grocertogo.mdb; "
strConnect += "Persist Security Info=False"

strCommand = "Select ProductName, UnitPrice FROM products"
objConnection = New OleDbConnection(strConnect)
objCommand = New OleDbDataAdapter(strCommand, ObjConnection)
objCommand.Fill(DataSet1, "products")
DataGrid1.DataSource = DataSet1.Tables("Products").DefaultView
DataGrid1.DataBind()
End Sub
</script>
<html>
<head>
<title>Data Grid Control Example</title>
</head>
<body>
<asp:DataGrid id="DataGrid1" runat="server" />
</body>
</html>

However, if I open VS, ASP.net web application, go to the sourcecode view,
paste it in, I get a bunch of errors. It doesn't even recogize " <script
language="vb" runat="server"> "

I know there has to be a way.

Thanks

Scott
 
A

Ashish M Bhonkiya

Hi,

to use this file in vs.net you just create a new page
go to the designer in vs.net 2003 select HTML and paste the contents of this
file to the newly created page.

thats all.

i tried this and it for the following code and worked for me.
if you need you can go a head and put the code in the script tags to the
respective events in the codebehind file.

Regards.
Ashish M Bhonkiya
 
S

Scott Allen

Scott : Are you pasting the code into the "HTML view" of an ASPX page?
If you paste this code into a .vb file you'll have errors, it wasn't
clear what you mean by source code view.
 
S

SL

If I open VS, ASP.net web application, goto project/add html page/
paste the code in place of what's there, I get no errors, just a browser
with nothing on it.

The first two lines are highlighted in yellow:
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>

Thanks

Scott
 
S

SL

Scott,
I've trying pasting into the .vb file and I get errors. I've also tried
adding an HTML page and it will run, but I get nothing but a blank browser.
If I run the file from the brower (created by notepad) it works.

I'm getting this code out of a Wrox book that doesn't even mention VS, so it
was probably the wrong book, but I'd like to learn how to run the examples
in VS if possible.

Thanks

Scott
 
S

Scott Allen

Hi Scott:

One of the problems is that this code belongs in an ASPX page without
a code behind file. By default VS.NET creates ASPX pages with a code
behind file.

Save the code you have below into a file with an ASPX extension. In
Visual Studio.NET you can right click a web project in Solution
Explorer and select "Add" -> "Add Existing Item" from the context
menu, then add the aspx file you've created. If VS.NET prompts you to
create a code behind file, answer no. You should be able to start
debugging and step through the code. Or right click the aspx in
solution explorer and select "View In Browser".

HTH,
 
A

Ashish M Bhonkiya

Hi,
If I open VS, ASP.net web application, goto project/add html page/
paste the code in place of what's there, I get no errors, just a browser
with nothing on it.

You need to add a webform and not and HTML Page. and repeat the same steps,
that should help.

Regards
Ashish M Bhonkiya
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top