Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I am converting an asp site to asp.net. I had one page that had a lot of email links for officers in a company. When I built the asp page rather than hard code the email address in the html I kept them in an include page and just included that on any page that needed an address. This made it easy when someone got promoted or left the company because I only had to change in one place.

 

So how do I emulate this in asp.net?

 

I created a VB class and put the variables in it. But how can I include this in my html page directive and how can I reference the variable within some html?

Wanna-Be C# Superstar
Posted

I don't really need a UI element. All I have is 6 string variables that I want to keep centralized and reference in my code.

 

Here is my class

 

 

Namespace functions

Public Class MailList

 

variables......

 

End Class

End Namespace

 

 

And then in my aspx page I have:

 

<%@ Import Namespace="Functions.MailList.vb" %>

 

in the directives at the top and then in my page I have:

 

<a href="mailto:" & <%=Functions.MailList.Prez()%> & "?Subject=stuff">President@yoyo.org</a>

 

 

I noticed that it put the () after my Prez. I guess it wants to see a function name???

Wanna-Be C# Superstar
Posted
I really don't have any functions. They are merely variables that don't change and I don't need to manipulate them. I have added them as read only properties of my class but I can't get them to import into the asp.net page for some reason.
Wanna-Be C# Superstar
Posted

Thank you so much for being patient kahlua001.

 

I got it hammered out. I had a namespace in there too so I had to modify your last line a tad

 

<%= myproject.mynamespace.sample.PresidentEmail %>

Wanna-Be C# Superstar
Posted

I couldn't agree with you more, Derek, that containing variables in the code behind page on the On_Load event is much more feasible and makes for a more efficient design. But in this case how would I go about doing that?

 

I have text in a span tag that I want to be inline with, and styled like, the text that gets generated from the variable call. I figured out how i could assign the variable to a label in the On_Load event and it seems easy enough. I just envision a web page where all of the text looks consistent except for these variables. It kind of detracts from their dynamic nature.

Wanna-Be C# Superstar
  • *Gurus*
Posted

Span elements should inherent their parent's attributes.

<span id="firstName" runat="server"></span>

Private Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
    firstName.InnerText = yourVariable
End Sub

You may have to cast the span element to a HtmlContainerControl prior to setting it's text.

Posted

Thanks Derek,

 

VS.NET is telling me that I can't use the span tag because I am inside a table.

 

Also the element isn't being recognized in the code behind page. I can't reference it as

 

firstname

 

or as Me.firstname

 

The cast won't accept it either.

 

But it does sound like this should work.

Wanna-Be C# Superstar
Posted

I finally hammered it out!! Thanks for your help Derek.

 

Here is what I have for html:

 

<td><span id="ctlPresidentElect" runat="server"></span></TD></TR>

 

What I was missing was a declaration in the 'Windows Generated' section like so:

 

Protected WithEvents ctlPresidentElect As HtmlGenericControl

 

And then in Page_Load:

 

ctlPresidentElect.InnerHtml = "<A href=" & "mailto:" & PrezElect & "?Subject=SureNough" & " >PresidentElect@dotnot.org</A>"

 

Thanks again, I appreciate it.

Wanna-Be C# Superstar

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...