Well... we could read the manuals and learn how ASP.NET is supposed be done... But ASP.NET has a pretty high learning curve. So, most of us will try to wing it. After all it still is ASP? Right?
Well, with a few of the main gotcha's handled you can sort of get away with that. That is what these pages are about.
DIM and other initialization statements typically go in a code block near the top of the pages code that looks like this.
<script runat="server">
Sub Page_Load()
'code here to run every time
Dim rowCount AS INT = 0
If NOT Page.IsPostBack Then
'code here only runs on first page load
else
'code here runs only on POSTBACK page loads
End If
End Sub
</script>
I usually place my code after the DW tags (i.e., <MM:DataSet ) and in the <head> tag. By the way, the code above is an Event Handler. But, don't get the idea that all your ONLOAD code should go here. Remember which is server side and client side, this is the server side.
Also notice the DIM statement has changed. ASP.NET insists that you tell it what type of variable you are defining. That is called 'Strong Variable Typing.' It helps reduce future 'logic' problems in your code. Whatever, you have to do it. For most of us the types INT and STRING will do most of what we need. You can Google for the other VB (not script) Types to get a list.
You can still use ASP's <% %> in .NET but not always. If the <% %> code section is outside a runAt="server" block, expect problems.
You can get away with many <%= something %> just about anywhere. What you can do inside the .NET version of the tag is very restricted. Plan to use the new <%# %>, which is not equivalent but works in most places where you are not outputting to the page stream (writing to the page).
I'll show you how I got an <ASP:DropDownList /> populated from a data set and added a couple of non-database-item selections to the list on the next page.
|