 |
| ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 1.0 and 1.1 Basics 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
|
|
|
|

August 25th, 2003, 01:53 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
simple button question
hopefully!
I'm new to asp.net and I'm playing around with buttons and labels.
-----------------------------------------
Here is my HTML code:
<form runat="server">
<asp:Label id="Label1" runat="server">Label</asp:Label><br />
<asp:Button id="Button1" runat="server" Text="Button"></asp:Button>
</form>
--------------------------------------
Here is my code behind:
Public Class WebForm1
Inherits System.Web.UI.Page
Protected WithEvents Label1 As System.Web.UI.WebControls.Label
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Response.Redirect("http://www.amazon.com")
End Sub
End Class
------------------------------------------------
When I click the button nothing happens. Can someone help me. Thanks in advance.
|
|

August 25th, 2003, 02:27 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi there,
There is no Handles Button1.Click following the Button1_Click method defintion.
Did you remove it? Or did Visual Studio do that? If sometimes seems to drop code when you switch views....
The definition should look like this:
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
HtH,
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
|
|

August 25th, 2003, 02:42 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
I removed it debugging it. It works now but only after I clicked "build solution". Is this required everytime I make a change to my code?
Thanks for your help.
|
|

August 25th, 2003, 03:04 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Yes, that is required.
ASP.NET pages are compiled and no longer just plain ol' script files. That means that any code you write in the Code Behind page, must be compiled to a DLL in your bin folder. Therefor, any change requires a explicit compile, or you could start the app using F5 to debug it (although that usually even takes more time)
Using Ctrl+Shift+B as a short-cut for Build Solution might speed up the process, as does a ridiculously fast machine......
Cheers,
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
|
|

August 25th, 2003, 03:31 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
Since the pages are compiled, I'm guessing we can't include files like in classic ASP... right?
|
|

August 25th, 2003, 03:47 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
If I am not mistaken, you can still include asp pages (or other static HTML pages) using the traditional include syntax.
However, ASP.NET introduces a few concepts that offer include functionality in a much better way. One of these is a Base Class that your page can inherit from (instead of from inheriting from the Page class). If you have nothing to do and lots of free time, follow this thread. It's over a year old but it's still alive. It has inspired my way of thinking about templates a lot.
Another, far easier resuable thingy are User Controls and Server Controls. User Controls are more or less simple HTML snippets with some added Code Behind functionality. Server Controls are like normal ASP controls (textbox, etc) and can be very powerful, but a bit difficult to implement right. Look at User Controls and Server Controls in the Samples and Quick Starts of the Framwork SDK for more info.
HtH,
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
|
|

August 25th, 2003, 03:47 PM
|
|
Authorized User
|
|
Join Date: Jul 2003
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
You only need to build you web every time you make a change if you are using Visual Studio to build your web/solution. If you are building your web in a more traditional (read free) text based web editor you will not need to build your web every time. the .Net Framework is capable of compiling the web when it is run. There some advatages to not developing in VS.Net.
|
|

August 25th, 2003, 03:55 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
Yes and no. ;) The whole concept of #include has been abandoned. Because of the way .Net works, you now can access all your helper functions/classes/etc from anywhere in the namespace hierarchies. Of course, many people's use of include files was for layout. .Net's (poor IMHO) solution to this is user controls.
I just did a test in VS.Net. I created an ASPX file with no code-behind. It looked like this...
Code:
<%
Dim sTestString as String = "Junk test string"
Response.Write("This is coming from the include file.")
Response.Write(sTestString)
%>
Then I created an ASP file.
Code:
<%
Response.Write("This is coming from the include file.")
Response.Write(sTestString)
%>
I then added these lines to an existing aspx webform...
It worked!
So I guess the technically accurate answer is: Yes you can still do includes. And you seem to be able to mix them up between ASP and ASPX. But, you really shouldn't do this. Given that an include would need to be an asp/x file that has just inline script in it, you defeat the power and advantage of compilation, intellisense, etc.
What are you intending to do with includes?
|
|

August 25th, 2003, 03:59 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
Quote:
quote:Originally posted by CraigJones
You only need to build you web every time you make a change if you are using Visual Studio to build your web/solution. If you are building your web in a more traditional (read free) text based web editor you will not need to build your web every time. the .Net Framework is capable of compiling the web when it is run. There some advatages to not developing in VS.Net.
|
This is not all entirely accurate. If you build your aspx with the code in a script tag in the aspx file itself, then indeed this is the case. The .Net framework will JIT compile your page code. However, if you use code-behind files, regardless of whether you are building them with VS.Net or Notepad, you still need to compile the . vb files into the DLL.
Peter
|
|

August 25th, 2003, 04:07 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Yes, Peter is completely right in this.
Also, when you use in-line script, you still need to wait until the is compiled. If the source of the new page doesn't match the source for the old page that has been compiled and stored (this is difficult language for "If you make a change" ;)), then the page will be recompiled by the framework, causing a delay anyway, but postponed to the moment you request it in the browser.
IMHO, the added benefits like easy Code Behind, Intelli Sense, Autocomplete, etc etc etc make VS.NET a pretty good tool for building applications. The "delay in compiling" might be just as long as for any other page with in-line ASP.NET script.
I just wish the Designer wasn't so buggy and didn't touch my code..... ;)
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
|
Similar Threads
|
| Thread |
Thread Starter |
Forum |
Replies |
Last Post |
| Simple Question |
JEHalm |
BOOK: Beginning Access VBA |
0 |
December 29th, 2005 10:42 AM |
| Simple Question |
dinosaur_uk |
VB.NET 2002/2003 Basics |
1 |
September 10th, 2004 09:43 AM |
| Simple Question |
MSK888 |
C# |
4 |
August 1st, 2004 12:12 AM |
|
 |