asp response.write in asp.net 
Author Message
 asp response.write in asp.net

Hi,

   I have been developing Classic ASP pages for a few years and have just
decieded to check out the asp.net stuff.
Maybe I have misunderstood a concept here and I am hoping that somebody
could be put straight.

As I understand it the code behind page should contain all of the server
side logic and none of this server side logic should be contained in the
.aspx file.

so in all of my old .asp I had the following code in the <head></head>
section of the page to write out a different base href depending on the
server I was running on.
=============================================
dim sWebDomain ,sBaseHref
sWebDomain = Request.ServerVariables("SERVER_NAME")

if sWebDomain  = "C3PO-2k" then
'We are on the development machine
        sBaseHref = "http://C3PO-2k/"
else if sWebDomain  = "Mars" then
'We are on the live machine
    sBaseHref = "http://Mars/"
else if sWebDomain  = "localhost"
'we are on my local machine
    sBaseHref = "http://Localhost/"
end if

response.write("<base href=' " & sBaseHref & "'>" & vbcrlf )
================================================

anyway my question is how i would go about puting this in my new asp.net
project. (where does it belong aspx file or aspx.vb file)
I had write that code renderblocks should not be used in asp.net.
i tried using a script block in the aspx page which gave an error.
should i use console.writeline????

I am coding using visual studio.net 2002.

any help or pointers in the right direction are very much appreciated.

cheers

martin



Wed, 05 Oct 2005 08:55:07 GMT  
 asp response.write in asp.net
I believe for things like that you can use asp.net literal control. So it
would look like this in your aspx:

<head>
    <asp:Literal id="MyBaseHref" runat="server"></asp:Literal>
</head>

And then in your code-behind on the page load do your logic:

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
        If Page.IsPostBack Then Return
        ....
        declare and initialize sBaseHref here
        ....
        MyBaseHref.Text = "<base href='" & sBaseHref & "'>"
    End Sub



Quote:
> Hi,

>    I have been developing Classic ASP pages for a few years and have just
> decieded to check out the asp.net stuff.
> Maybe I have misunderstood a concept here and I am hoping that somebody
> could be put straight.

> As I understand it the code behind page should contain all of the server
> side logic and none of this server side logic should be contained in the
> .aspx file.

> so in all of my old .asp I had the following code in the <head></head>
> section of the page to write out a different base href depending on the
> server I was running on.
> =============================================
> dim sWebDomain ,sBaseHref
> sWebDomain = Request.ServerVariables("SERVER_NAME")

> if sWebDomain  = "C3PO-2k" then
> 'We are on the development machine
>         sBaseHref = "http://C3PO-2k/"
> else if sWebDomain  = "Mars" then
> 'We are on the live machine
>     sBaseHref = "http://Mars/"
> else if sWebDomain  = "localhost"
> 'we are on my local machine
>     sBaseHref = "http://Localhost/"
> end if

> response.write("<base href=' " & sBaseHref & "'>" & vbcrlf )
> ================================================

> anyway my question is how i would go about puting this in my new asp.net
> project. (where does it belong aspx file or aspx.vb file)
> I had write that code renderblocks should not be used in asp.net.
> i tried using a script block in the aspx page which gave an error.
> should i use console.writeline????

> I am coding using visual studio.net 2002.

> any help or pointers in the right direction are very much appreciated.

> cheers

> martin



Wed, 05 Oct 2005 13:23:01 GMT  
 asp response.write in asp.net
Hi Michael,

Thanks for that bit of advice. it is exactly the thing i was looking for.

I have now decided that maybe a should place a class betwwen
System.Web.UI.Page and the class in my code behind page.

The class in my code behing page will inherit from my middle tier class
which in turn inherits from System.Web.UI.Page.

In my new class I am placing the basehref and any other references to
outside sources

eg Javascript file and style sheets

that occur on every page.

cheers

Martin


Quote:
> I believe for things like that you can use asp.net literal control. So it
> would look like this in your aspx:

> <head>
>     <asp:Literal id="MyBaseHref" runat="server"></asp:Literal>
> </head>

> And then in your code-behind on the page load do your logic:

>     Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Load
>         If Page.IsPostBack Then Return
>         ....
>         declare and initialize sBaseHref here
>         ....
>         MyBaseHref.Text = "<base href='" & sBaseHref & "'>"
>     End Sub



> > Hi,

> >    I have been developing Classic ASP pages for a few years and have
just
> > decieded to check out the asp.net stuff.
> > Maybe I have misunderstood a concept here and I am hoping that somebody
> > could be put straight.

> > As I understand it the code behind page should contain all of the server
> > side logic and none of this server side logic should be contained in the
> > .aspx file.

> > so in all of my old .asp I had the following code in the <head></head>
> > section of the page to write out a different base href depending on the
> > server I was running on.
> > =============================================
> > dim sWebDomain ,sBaseHref
> > sWebDomain = Request.ServerVariables("SERVER_NAME")

> > if sWebDomain  = "C3PO-2k" then
> > 'We are on the development machine
> >         sBaseHref = "http://C3PO-2k/"
> > else if sWebDomain  = "Mars" then
> > 'We are on the live machine
> >     sBaseHref = "http://Mars/"
> > else if sWebDomain  = "localhost"
> > 'we are on my local machine
> >     sBaseHref = "http://Localhost/"
> > end if

> > response.write("<base href=' " & sBaseHref & "'>" & vbcrlf )
> > ================================================

> > anyway my question is how i would go about puting this in my new asp.net
> > project. (where does it belong aspx file or aspx.vb file)
> > I had write that code renderblocks should not be used in asp.net.
> > i tried using a script block in the aspx page which gave an error.
> > should i use console.writeline????

> > I am coding using visual studio.net 2002.

> > any help or pointers in the right direction are very much appreciated.

> > cheers

> > martin



Wed, 05 Oct 2005 17:40:05 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Survey on ASP/VS6.0 versus ASP.NET/VS.NET

2. Visual Basic.NET , ASP or ASP.NET

3. VB6/ASP vs .NET/ASP.NET development

4. Writing a file out to the response object using asp

5. output response.write to a specific cell in an ASP page

6. Auto Refresh from ASP to response.write

7. DHTML/ASP Response.Write question

8. Com+ and writing cookies using the ASP Response object

9. Response.Redirect and Validation Controls with ASP.NET

10. Application State in ASP and ASP.NET

11. ASP Request Object into ASP.Net

12. ASP - ASP.NET quick question about including files..

 

 
Powered by phpBB® Forum Software