Helper Functions

One of the most common questions on the net about ASP.Net, when coming from a Classic ASP background, is how to handle situations in which conditional programming is necessary. For instance, in Classic ASP, if you had this code:

If recordset("fieldName") <> "" Then
 ' do this
Else
 ' do this
End if

Since, in ASP.Net, we do not have the sequential code, coming throught the page, like it did with Classic ASP, sometimes we’ll have a label or textbox (or whatever), with the same field information which would have been previously contained in‘recordset(“fieldName”)’

.

To handle this, we would create a helper function, in our code section. So, in this case, let’s call the Function ‘CheckItem’. In the tag, we’d start with something like this:

<asp:Label ID="Label1" Text='<%# Container.DataItem("fieldName") %>' Runat="server" />

Next, we’ll add the code for the function:
Continues…

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>