Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Pass double quote from VB to HTML

Pass double quote from VB to HTML

Scheduled Pinned Locked Moved ASP.NET
htmlsysadminhelp
14 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J jamesbronw

    can i do that inside a do while loop like this... Do While lbl <= 7 Dim newlbl As New Label newlbl.ID = "newlbl" & lnum newlbl.Text = lnum newlbl.BackColor = System.Drawing.Color.Blue newlbl.BorderStyle = BorderStyle.Inset newlbl.BorderColor = System.Drawing.Color.Black newlbl.BorderWidth.Pixel(1) Page.Controls.Add(newlbl)

    J Offline
    J Offline
    Jesse Squire
    wrote on last edited by
    #5

    Absolutely. Just keep in mind that dynamic controls need to be recreated each trip back to the server. ASP.NET will not recreate them on postback. --Jesse

    J 1 Reply Last reply
    0
    • J Jesse Squire

      Absolutely. Just keep in mind that dynamic controls need to be recreated each trip back to the server. ASP.NET will not recreate them on postback. --Jesse

      J Offline
      J Offline
      jamesbronw
      wrote on last edited by
      #6

      well that code i posted doesnt work. Nothing shows up on the screen

      J M 2 Replies Last reply
      0
      • J jamesbronw

        well that code i posted doesnt work. Nothing shows up on the screen

        J Offline
        J Offline
        Jesse Squire
        wrote on last edited by
        #7

        The equivilent C# code works just fine for me. Two things that strike me from the code you posted. The line newlbl.BorderWidth.Pixel(1) isn't correct. The code should read: newlbl.BorderWidth = Unit.Pixel(1), as Pixel is a static (shared) method of the Unit class. I also don't see an End While in your code. I don't know if either is the cause of your problems, but they should be fixed none the less. You really should consider setting Option Explicit and Option Strict on all of the time, if you don't already. They will save you from alot of subtle problems. The rest of your example looks fine to me. If correcting the two points that I mentioned doesn't fix your problem, I'd suggest you start debugging. For example, you don't see anything in the browser. Have you done a "view source" and checked the HTML? Just in case you find it helpful, here is the C# translation of your code that I used to verify.

        private void Page_Load(object sender, System.EventArgs e)

        {

        Label label = null;

        for(int index = 0; index < 7; index++)

        {

        label = new Label();

        label.Text = index.ToString();

        label.BackColor = System.Drawing.Color.Blue;

        label.BorderStyle = BorderStyle.Inset;

        label.BorderColor = System.Drawing.Color.Black;

        label.BorderWidth = Unit.Pixel(1);

        J 1 Reply Last reply
        0
        • J Jesse Squire

          The equivilent C# code works just fine for me. Two things that strike me from the code you posted. The line newlbl.BorderWidth.Pixel(1) isn't correct. The code should read: newlbl.BorderWidth = Unit.Pixel(1), as Pixel is a static (shared) method of the Unit class. I also don't see an End While in your code. I don't know if either is the cause of your problems, but they should be fixed none the less. You really should consider setting Option Explicit and Option Strict on all of the time, if you don't already. They will save you from alot of subtle problems. The rest of your example looks fine to me. If correcting the two points that I mentioned doesn't fix your problem, I'd suggest you start debugging. For example, you don't see anything in the browser. Have you done a "view source" and checked the HTML? Just in case you find it helpful, here is the C# translation of your code that I used to verify.

          private void Page_Load(object sender, System.EventArgs e)

          {

          Label label = null;

          for(int index = 0; index < 7; index++)

          {

          label = new Label();

          label.Text = index.ToString();

          label.BackColor = System.Drawing.Color.Blue;

          label.BorderStyle = BorderStyle.Inset;

          label.BorderColor = System.Drawing.Color.Black;

          label.BorderWidth = Unit.Pixel(1);

          J Offline
          J Offline
          jamesbronw
          wrote on last edited by
          #8

          Thanks for all your help. It is greatly appriciated. I have looked at the source code and there is nothing there that should be. I have no idea whats going on with this haha. I suppose i'll have to find another way to do what i need done. Again thanks Tommy

          J 1 Reply Last reply
          0
          • J jamesbronw

            Thanks for all your help. It is greatly appriciated. I have looked at the source code and there is nothing there that should be. I have no idea whats going on with this haha. I suppose i'll have to find another way to do what i need done. Again thanks Tommy

            J Offline
            J Offline
            Jesse Squire
            wrote on last edited by
            #9

            My pleasure. I hope things work out for you. :) --Jesse

            1 Reply Last reply
            0
            • J jamesbronw

              well that code i posted doesnt work. Nothing shows up on the screen

              M Offline
              M Offline
              minhpc_bk
              wrote on last edited by
              #10

              Hi there, There are two simple things come to mind: + The code inside the while loop does not actually get reached at all. You can simply run your application in debug mode and see if that happens. + If you put this code in a custom control, then you can check if the custom control is added to the page.

              J 1 Reply Last reply
              0
              • M minhpc_bk

                Hi there, There are two simple things come to mind: + The code inside the while loop does not actually get reached at all. You can simply run your application in debug mode and see if that happens. + If you put this code in a custom control, then you can check if the custom control is added to the page.

                J Offline
                J Offline
                jamesbronw
                wrote on last edited by
                #11

                Ok if i put it straight into my VB form code it renders it. If i put it into a sub procedure and call it from the HTML using the <% %> it doesnt create my new objects. This is all so new to me. Do you know why it would do this?

                M J 2 Replies Last reply
                0
                • J jamesbronw

                  Ok if i put it straight into my VB form code it renders it. If i put it into a sub procedure and call it from the HTML using the <% %> it doesnt create my new objects. This is all so new to me. Do you know why it would do this?

                  M Offline
                  M Offline
                  minhpc_bk
                  wrote on last edited by
                  #12

                  The reason those label controls cannot be seen at the client side is that the code to create those controls runs after the Page_PreRender event of the Page life cycle. When the page contents are rendered at the Render phase, the labels are not actually added to the page so you don't see them on the screen, you can see that when running your application in debug mode. Here, you may want to place the labels at the place where you put the code <% %> in the page, right? There are two simple ways to work around this: + You can use a container such as PlaceHolder control in the page where you want to put the labels, the sample code in code behind is like this:

                  Private Sub Page\_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
                      'Put user code to initialize the page here
                      RenderLabelList1()
                  End Sub
                             
                  Protected Sub RenderLabelList1()
                      Dim lnum As Integer = 0
                      Do While lnum <= 7
                          Dim newlbl As New Label
                          newlbl.ID = "newlbl" & lnum
                          newlbl.Text = lnum
                          newlbl.BackColor = System.Drawing.Color.Blue
                          newlbl.BorderStyle = BorderStyle.Inset
                          newlbl.BorderColor = System.Drawing.Color.Black
                          newlbl.BorderWidth.Pixel(1)
                          'Page.Controls.Add(newlbl)
                          PlaceHolder1.Controls.Add(newlbl)
                          lnum = lnum + 1
                      Loop
                  End Sub
                  

                  + You can write out the rendered html markup of the labels to the page, the sample code in code-behind

                  Protected Function RenderLabelList() As String
                      Dim lnum As Integer = 0
                      Dim writer As System.IO.StringWriter = New System.IO.StringWriter
                      Dim buffer As System.Web.UI.HtmlTextWriter = New System.Web.UI.HtmlTextWriter(writer)
                      Do While lnum <= 7
                          Dim newlbl As New Label
                          newlbl.ID = "newlbl" & lnum
                          newlbl.Text = lnum
                          newlbl.BackColor = System.Drawing.Color.Blue
                          newlbl.BorderStyle = BorderStyle.Inset
                          newlbl.BorderColor = System.Drawing.Color.Black
                          newlbl.BorderWidth.Pixel(1)
                          'Page.Controls.Add(newlbl)
                          newlbl.RenderControl(buffer)
                          lnum = lnum + 1
                      Loop
                           
                      Return writer.ToString()
                  End Function
                  

                  The markup in the web page for both two ways is simple like this:

                  <form id="Form1" method="post" runat="server">
                  <asp:PlaceHolder id="Pl

                  1 Reply Last reply
                  0
                  • J jamesbronw

                    Ok if i put it straight into my VB form code it renders it. If i put it into a sub procedure and call it from the HTML using the <% %> it doesnt create my new objects. This is all so new to me. Do you know why it would do this?

                    J Offline
                    J Offline
                    Jesse Squire
                    wrote on last edited by
                    #13

                    Minh's advice is dead-on. I just wanted to add one additional point. The use of <% %> is not considered a best practice and should be avoided if at all possible. Each time a <% %> is encountered, context switching occurrs which carries a performance penalty. If you need to inject controls at a certain location, you would be served far better by placing a container object into the HTML and manipulating it from the code-behind. For example, you could place a panel where you need to add the labels by doing <asp:Panel id = "labelHolder" runat = "server" />. In your code-behind, you would declare a protected variable of type Panel with the same name as the id: Dim labelHolder as Panel. To place your labels you would just add them to the panel's control collection: labelHolder.Controls.Add(myLabel). Hope that helps. :) --Jesse

                    J 1 Reply Last reply
                    0
                    • J Jesse Squire

                      Minh's advice is dead-on. I just wanted to add one additional point. The use of <% %> is not considered a best practice and should be avoided if at all possible. Each time a <% %> is encountered, context switching occurrs which carries a performance penalty. If you need to inject controls at a certain location, you would be served far better by placing a container object into the HTML and manipulating it from the code-behind. For example, you could place a panel where you need to add the labels by doing <asp:Panel id = "labelHolder" runat = "server" />. In your code-behind, you would declare a protected variable of type Panel with the same name as the id: Dim labelHolder as Panel. To place your labels you would just add them to the panel's control collection: labelHolder.Controls.Add(myLabel). Hope that helps. :) --Jesse

                      J Offline
                      J Offline
                      jamesbronw
                      wrote on last edited by
                      #14

                      Thanks to both of you. I am now able to atleast get the labels on the page! haha. Now i just need to figure out how to get them in the rows and columns needed. lol. Again, thanks for all your time and help Tommy

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups