Wrox Programmer Forums
|
ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.1 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 7th, 2003, 01:06 AM
Registered User
 
Join Date: Jul 2003
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default help

In every asp.net book there is written code with fist lain
<%import namespace=etc.....%>
When I try to write code I can't get help screen. I am always using in first line imports system.data or like that.
HOW I can write same code as in the book. Probably I should downloaded some software or something like that
Please help


 
Old October 7th, 2003, 12:33 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Not sure I understand.. What exactly is the problem? What help screen do you refer to?

Please be a bit more specific about your problem.....


Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old October 7th, 2003, 01:14 PM
Registered User
 
Join Date: Jul 2003
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Imar
In every wrox book (ASP.Net) is written code like this
%@ Import namespace="System.Data.SqlClient" %>
<%@ Import namespace="System.Data" %>
<%@ Page CodeBehind="Radio_button.aspx.vb" Language="vb"
AutoEventWireup="false" Inherits="WebApplication7.Radio_button" %>
<HTML>
 <HEAD>
  <title>Using Radio Buttons</title>
 </HEAD>
 <body>
  <h3>Using Radio Buttons</h3>
  <form runat="server">
   <asp:RadioButtonList id="radEmployees" AutoPostBack="True" Rows="5"
OnSelectedIndexChanged="subListChange" runat="server" />
   <br>
   <br>
   <asp:DataGrid id="dgEmployee" runat="server" />
  </form>
  <script language="VB" runat="server">
Sub Page_Load(Source As Object, E As EventArgs)
  If Not IsPostBack Then
    Dim strConnection As String =
"server=dragan;database=northwind;uid=sa;pwd="

    Dim strSQLforListBox As String = "SELECT LastName, EmployeeID "
    strSQLforListBox += "FROM Employees ORDER BY LastName"

    Dim objConnection As New SqlConnection(strConnection)
    Dim objCommand As New SqlCommand(strSQLforListBox, objConnection)

    objConnection.Open()
    radEmployees.DataSource = objCommand.ExecuteReader()
    radEmployees.DataTextField = "LastName"
    radEmployees.DataValueField = "EmployeeID"
    radEmployees.DataBind()
    objConnection.Close()
  End If
End Sub

-------

My question is how I can write this code. On the screen on the button left
corner I have HTML and design mode. If I chose design mode and type for
example RadEmploee. computer doesn't give me options. like datasource or
datatextfield and etc.. But If I click right button and chose option view
code I got screen same as visual basic 6.0 and I can chose object and events
from top screen .
My question How I can write same code as in the book. Probably I didn't
install something.
regards

 
Old October 7th, 2003, 01:21 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Ah, so the problem is that you are using VS.Net! (Well, that's not a problem it's actually way better than notepad. :)

Best approach is to use VS to create a new webform. This will set everything up the right way... then you can put the HTML into the *.aspx file, and the code into the *.aspx.vb file.

Once you create a web form, you'll see where things go cause VS will have the basics done for you (page_load will already be there and ready for your code.)

Peter
 
Old October 7th, 2003, 01:37 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Yeah, the code from the book is "inline" code; where the C# or VB.NET code is placed between script tags and mixed with HTML. This is a bit like it was in classic ASP.

Visual Studio uses a different model, called Code Behind where the Code for the page is in a separate .cs or .vb file. Personally, I prefer that method over inline script as it's easier to read and maintain. Check out this thread for a more detailed opinion.

When you have Visual Studio, it's often a pain to have it write inline script. By default, it hooks up a Code Behind file for you automatically. You can use inline script, but I wouldn't do it if I were you.

Here are a few steps you need to perform to transfer an inline page to a code behind page:

1. Create a new page in VS.NET with Code Behind.
2. Move all Import Namespace.... from the inline ASPX page and rename Import to Imports when you use VB.NET or to using in a C# project
3. Move all Sub / Function declarations to the Code Behind
4. Clean up the inline page. Make sure that any method it refers to is Public in the Code Behind.

That's about it. If you have an example page or a specific question about an inline page, feel free to post them here.

Cheers,

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.









Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.