How's this done in .Net

  • Thread starter Thread starter Rob Venable
  • Start date Start date
R

Rob Venable

Hi everyone,
I'm migrating to .Net and in Classic ASP I build registration forms that
submits to itself and calls different subroutines that contain HTML code
based on which step they're on. This is all done on one asp page and
contains multiple subroutines.

Can you do this in ASP.Net?
Do you have to put your subroutines within <script> tags?

Thaks
Rob
 
In .NET, there is no scripting in Active SERVER Pages. All scripting is client side

The idea that your form is going to repeatedly be submitted back to the page that rendered it suggests what is called "PostBack" in ASP.NET. You can have server-side events that are raised according to exactly what the user did before submitting the form. For example, a given text box could have been changed or an item was selected from a list box. Server-side code (compiled code, not script) can be written to deal with each of these events. This code can be kept in subroutines on the page, in "code-behind" files, or encapsulated into object classes. ASP.NET provides Web Control classes that render standard HTML tags and you can even derive your own classes that render HTML exactly the way you want it

Some events (typically a button click) raise a "PostBack" event. This means that the form (which appears to the browser just like any old HTML form) is submitted back to your .aspx page (has to be the same .aspx file that originally rendered the page). Your code then handles a whole series of "cached" events that store and/or manipulate the submitted data as required

Alternatively, HTML controls can be handled with client-side code, just as with classic ASP

It should be fairly easy to re-code your HTML controls into ASP.NET controls and, once you've done that, it's very easy to make controls visible (i.e. rendered or totally not rendered) with your subroutine code. But if the darn thing works and you don't need any major enhancements, I would probably be inclined to leave it alone. Even if you're going to need to run ASP.NET apps on the same web site, classic and .NET ASP are supposed to be able to co-exist with out any issues

But it will be a good learning experience, for sure.
 
I remember when I first tried to convert from ASP3 to .NET. It requires
a totally different mindset. Fortunately, I had experience writing VB
desktop apps. If you have done that also, you'll be a step ahead.

The difference between ASP3 and ASP.NET is like the difference between
QuickBasic and Visual Basic. (Has it been that long?) The former is
more procedural (no matter how nicely you structure it) and the latter
is event-driven.

With your form, which sounds like a wizard interface, what you could do
is build all your screens in one ASPX page, separated by <asp:Panel />
elements, like:

<asp:panel runat=server id="panStep1" visible="true">
<asp:textbox runat=server id="txtName" /><br>
<asp:button runat=server id="cmdNext1" text="Next>>" />
</asp:panel>

<asp:panel runat=server id="panStep2" visible="false">
<asp:textbox runat=server id="txtAddress" /><br>
<asp:button runat=server id="cmdNext2" text="Next>>" />
</asp:panel>

<asp:panel runat=server id="panStep3" visible="false">
<asp:textbox runat=server id="txtEmail" /><br>
<asp:button runat=server id="cmdNext3" text="Next>>" />
</asp:panel>

Then you write an event handler for each <asp:button /> element. This
is where the event-driven stuff comes in. You'll have three subs, one
for each button. Each one will set the .Visible property of the panels
to show or hide the respective screen (panel) of the wizard. Notice how
the first panel is visible and the next two are not.

Don't think in the sense of inserting code at a certain place when you
run a sub, that's not how .NET works. You structure all your screens
beforehand in the ASPX and turn sections on and off. If you want to
insert code modules in multiple places, you will want to research web
controls, but first things first. You will probably rethink how your
structure your pages. I used to put the List, Edit, and Save code all
in one ASP page, but have since broken the List section into its own
ASPX page for efficiency and maintainability.

Hopefully that turns on the lightbulb. I expect if you're a long-time
ASP3 person, you'll fight with ASP.NET trying to make it behave like
what you're used to. It's a losing battle. Now go out there and raise
some events.
 
Back
Top