Results 1 to 19 of 19

Thread: vb .net (asp .net) app... response.write

  1. #1

    Thread Starter
    Hyperactive Member pgrimes's Avatar
    Join Date
    Aug 2001
    Location
    sacramento
    Posts
    342

    vb .net (asp .net) app... response.write

    I feel this falls into the 'stupid question' category, but the time has come that I must ask it.

    I have this code from my vb .net (asp .net) application (created in visual studio .net)
    VB Code:
    1. Public Class WebForm1
    2.     Inherits System.Web.UI.Page
    3.  
    4. #Region " Web Form Designer Generated Code "
    5.  
    6.     'This call is required by the Web Form Designer.
    7.     <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    8.  
    9.     End Sub
    10.  
    11.     Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
    12.         'CODEGEN: This method call is required by the Web Form Designer
    13.         'Do not modify it using the code editor.
    14.         InitializeComponent()
    15.     End Sub
    16.  
    17. #End Region
    18.  
    19.     Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    20.         Response.Write("<table><tr><td>Why does this show up above the html tags</td></tr></table>")
    21.     End Sub
    22.  
    23. End Class



    Why does my response.write show get written above every other tag on the page... like this:
    [Results]
    Code:
    <table><tr><td>Why does this show up above the other tags?</td></tr></table>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    	<HEAD>
    		<title>WebForm1</title>
    		<meta name="GENERATOR" content="Microsoft Visual Studio.NET 7.0">
    		<meta name="CODE_LANGUAGE" content="Visual Basic 7.0">
    		<meta name="vs_defaultClientScript" content="JavaScript">
    		<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
    	</HEAD>
    	<body MS_POSITIONING="GridLayout">
    		<form name="Form1" method="post" action="WebForm1.aspx" id="Form1">
    <input type="hidden" name="__VIEWSTATE" value="dDwtMTI3OTMzNDM4NDs7PuIeAj03w2/SZE+efTMFhqIXJ3Ap" />
    
    		</form>
    	</body>
    </HTML>

    How do I make the stuff from my response.write get written inside of the <body> tags on the resulting page????

    My guess is that I need to stick some 'runat=server' stuff somewhere, but I don't know where.

    thanks!

  2. #2
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    use placeholder control then you can set its value in page load

    stick this where you need it

    <asp:PlaceHolder id="myPlace" runat="server"/>


    in page load, just say

    myPlace.Text = "<table><tr><td>Why does this show up above the html tags</td></tr></table>"
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  3. #3

    Thread Starter
    Hyperactive Member pgrimes's Avatar
    Join Date
    Aug 2001
    Location
    sacramento
    Posts
    342
    aha. Sounds good... now for the massive restructuring on all of my projects

    *doh*


    thanks again.

  4. #4
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    your welcome.

    ASP .NET can be a bit tricky a times with knowing what controls to use to avoid using inline asp tags <% %>
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  5. #5

    Thread Starter
    Hyperactive Member pgrimes's Avatar
    Join Date
    Aug 2001
    Location
    sacramento
    Posts
    342
    hmm... where do I put this:
    <asp:PlaceHolder id="myPlace" runat="server"/>
    in the aspx.vb code?

    Just to be clear, the code that I posted second in my original post (labeled "results") is what I get when I 'view source' after the WebForm1.aspx is run.

  6. #6
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    you put it where the html should appear.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  7. #7

    Thread Starter
    Hyperactive Member pgrimes's Avatar
    Join Date
    Aug 2001
    Location
    sacramento
    Posts
    342
    Sorry, I'm not gettin' it.

    Here's my aspx.vb code again:
    VB Code:
    1. Public Class WebForm1
    2.     Inherits System.Web.UI.Page
    3.  
    4. #Region " Web Form Designer Generated Code "
    5.  
    6.     'This call is required by the Web Form Designer.
    7.     <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    8.  
    9.  
    10.     End Sub
    11.  
    12.     Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
    13.         'CODEGEN: This method call is required by the Web Form Designer
    14.         'Do not modify it using the code editor.
    15.         InitializeComponent()
    16. <asp:PlaceHolder id="myPlace" runat="server"/>
    17.     End Sub
    18.  
    19. #End Region
    20.  
    21.     Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    22.  
    23.         myPlace.Text = "<table><tr><td>Why does this show up above the html tags</td></tr></table>"
    24.  
    25.     End Sub
    26.  
    27. End Class

    Everywhere I put '<asp:PlaceHolder id="myPlace" runat="server"/>' in that code, it has problems with it. I'm confused I guess.

  8. #8
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    no you dont stick it in subs, you put it in the actual html code area

    for example

    <html>
    <body>
    <asp:PlaceHolder blah blah blah..../>
    </body>
    </html>

    This is called a web form control. You may want to read up on them as they are VERY helpful and powerful.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  9. #9
    Member
    Join Date
    Aug 2002
    Posts
    58
    I think the problem is the load is the first thign run. How to fix i am nto sure, haven't looked into it yet.

    did youcreate the page load event? You shoudl move that code to another place, out side of the load.

    I will experiment when ido a fresh xp/.net install and let you knwo my results
    -------------------------------
    StupidMonkee

  10. #10

    Thread Starter
    Hyperactive Member pgrimes's Avatar
    Join Date
    Aug 2001
    Location
    sacramento
    Posts
    342
    Oh... I just noticed something that I haven't seen before. I've always double clicked the webform when it shows up in vs .net. I just right clicked on the webform and clicked on 'View HTML Source'.

    Now I see where I need to put '<asp:PlaceHolder id="myPlace" runat="server"/>'.

    I didn't know that I had access to the html source of the webform.aspx. Until just now, I had only seen it by clicking view source in ie after the aspx was run.





    Thanks a ton for all of your quick replies!

  11. #11
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    you welcome, and just so you dont get confused, after putting in that <asp;PlaceHolder, if you then view the requested pages source, you will not see that <asp:Placeholder. it will be replaced with the html you set as the .Text property.

    Just some FYI to help you better understand how Web Form controls work.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  12. #12

    Thread Starter
    Hyperactive Member pgrimes's Avatar
    Join Date
    Aug 2001
    Location
    sacramento
    Posts
    342
    right right

    kewl kewl

  13. #13

    Thread Starter
    Hyperactive Member pgrimes's Avatar
    Join Date
    Aug 2001
    Location
    sacramento
    Posts
    342
    k... one more question. In the html portion of WebForm1.aspx, I have this:
    Code:
    <%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm1.aspx.vb" Inherits="example1.WebForm1"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    	<HEAD>
    		<title>WebForm1</title>
    		<meta name="GENERATOR" content="Microsoft Visual Studio.NET 7.0">
    		<meta name="CODE_LANGUAGE" content="Visual Basic 7.0">
    		<meta name="vs_defaultClientScript" content="JavaScript">
    		<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
    	</HEAD>
    	<body MS_POSITIONING="GridLayout">
    		<form id="Form1" method="post" runat="server">
    	<asp:PlaceHolder id="myPlace" runat="server"/>
    		</form>
    	</body>
    </HTML>
    In WebForm1.aspx.vb, I have this:
    VB Code:
    1. Public Class WebForm1
    2.     Inherits System.Web.UI.Page
    3.  
    4. #Region " Web Form Designer Generated Code "
    5.  
    6.     'This call is required by the Web Form Designer.
    7.     <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    8.  
    9.     End Sub
    10.  
    11.     Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
    12.         'CODEGEN: This method call is required by the Web Form Designer
    13.         'Do not modify it using the code editor.
    14.         InitializeComponent()
    15.  
    16.     End Sub
    17.  
    18. #End Region
    19.  
    20.     Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    21.  
    22.         'Says "Name 'myPlace' is not decalred.
    23.         myPlace.Text = "<table><tr><td>Why does this show up above the html tags</td></tr></table>"
    24.  
    25.     End Sub
    26.  
    27. End Class

    It says that myPlace is not declared. Should this be happening? What do I declare it as?

  14. #14
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    oh you are using codebehind..

    right below this line
    Inherits System.Web.UI.Page


    put

    Public myPlace As System.Web.UI.WebControls.PlaceHolder
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  15. #15

    Thread Starter
    Hyperactive Member pgrimes's Avatar
    Join Date
    Aug 2001
    Location
    sacramento
    Posts
    342
    hmm... two problems now...
    one is here:
    Public myPlace As System.Web.UI.WebControls.PlaceHolder

    myPlace is underlined, and gives error:
    'myPlace' is already declared as 'Protected Dim WithEvents myPlace As System.Web.UI.WebControls.PlaceHolder' in this class
    The other is here:
    myPlace.Text
    that ^ is underlined and gives error:
    'Text' is not a member of 'System.Web.UI.WebControls.PlaceHolder'

  16. #16
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    oopss..i fudges up..I gave you the wrong control name..change PlaceHolder to Literal...

    That should do it..I hope.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  17. #17

    Thread Starter
    Hyperactive Member pgrimes's Avatar
    Join Date
    Aug 2001
    Location
    sacramento
    Posts
    342
    TADDAAA....
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    	<HEAD>
    		<title>WebForm1</title>
    		<meta name="GENERATOR" content="Microsoft Visual Studio.NET 7.0">
    		<meta name="CODE_LANGUAGE" content="Visual Basic 7.0">
    		<meta name="vs_defaultClientScript" content="JavaScript">
    		<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
    	</HEAD>
    	<body MS_POSITIONING="GridLayout">
    		<form name="Form1" method="post" action="WebForm1.aspx" id="Form1">
    <input type="hidden" name="__VIEWSTATE" value="dDwtMjM2MzU3MjA2O3Q8O2w8aTwxPjs+O2w8dDw7bDxpPDE+Oz47bDx0PHA8bDxUZXh0Oz47bDxcPHRhYmxlXD5cPHRyXD5cPHRkXD5XaHkgZG9lcyB0aGlzIHNob3cgdXAgYWJvdmUgdGhlIGh0bWwgdGFnc1w8L3RkXD5cPC90clw+XDwvdGFibGVcPjs+Pjs7Pjs+Pjs+Pjs+BONwb6kb293q1honbKd2Srrv0bQ=" />
    
    			<table><tr><td>Why does this show up above the html tags</td></tr></table>
    		</form>
    	</body>
    </HTML>
    Thanks a ton man . That seems to have done the trick.

  18. #18
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    w00t!
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  19. #19

    Thread Starter
    Hyperactive Member pgrimes's Avatar
    Join Date
    Aug 2001
    Location
    sacramento
    Posts
    342

    *resolved* :) vb .net (asp .net) app...

    *resolved*

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width