Converting html string to object

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Wouter vanEck

    Converting html string to object

    Hi,

    I need to find a way to read a html type string from a database and add it
    to a placeholder control on the page and then I need to be able to populate
    the fields that were in that html string at run time.

    The html string may look like this "<table><tr><td >First Name</td><td><input
    name=_firstname runat=server id=_firstname ....></td></tr></table>"

    Is there a way to convert this string into an object which you could access
    like _firstname.text or _firstname.inne rhtml, any thing to being able to set
    the value would be great.

    Is there anyone who knows about an article or has an idea how to go about
    doing this??

    Thanks,

    Wouter


  • vMike

    #2
    Re: Converting html string to object


    "Wouter vanEck" <wouter.vaneck@ smart-quotes.com> wrote in message
    news:uPu7bVO9EH A.2196@TK2MSFTN GP11.phx.gbl...[color=blue]
    > Hi,
    >
    > I need to find a way to read a html type string from a database and add it
    > to a placeholder control on the page and then I need to be able to[/color]
    populate[color=blue]
    > the fields that were in that html string at run time.
    >
    > The html string may look like this "<table><tr><td >First[/color]
    Name</td><td><input[color=blue]
    > name=_firstname runat=server id=_firstname ....></td></tr></table>"
    >
    > Is there a way to convert this string into an object which you could[/color]
    access[color=blue]
    > like _firstname.text or _firstname.inne rhtml, any thing to being able to[/color]
    set[color=blue]
    > the value would be great.
    >
    > Is there anyone who knows about an article or has an idea how to go about
    > doing this??
    >
    > Thanks,
    >
    > Wouter[/color]
    You can put a placeholder (say it is called plc1) on a page and then in code
    do the following
    plc1.controls.a dd(New literalcontrol( yourhtmltext))

    Then on postback get the request.form("_ firstname") . Take the runat out of
    the hmtltext


    Comment

    • Wouter vanEck

      #3
      Re: Converting html string to object

      Hi,

      Thanks for your quick response but I was actually trying to push a value to
      the field. The reading part is easy, just like you said, but I need to be
      able to populate the field after a postback.

      Wouter

      "vMike" <MichZaelY.GeZo rgeY@noZorY.geZ waYrrenY.com> wrote in message
      news:crmk8h$j02 $1@ngspool-d02.news.aol.co m...[color=blue]
      >
      > "Wouter vanEck" <wouter.vaneck@ smart-quotes.com> wrote in message
      > news:uPu7bVO9EH A.2196@TK2MSFTN GP11.phx.gbl...[color=green]
      > > Hi,
      > >
      > > I need to find a way to read a html type string from a database and add[/color][/color]
      it[color=blue][color=green]
      > > to a placeholder control on the page and then I need to be able to[/color]
      > populate[color=green]
      > > the fields that were in that html string at run time.
      > >
      > > The html string may look like this "<table><tr><td >First[/color]
      > Name</td><td><input[color=green]
      > > name=_firstname runat=server id=_firstname ....></td></tr></table>"
      > >
      > > Is there a way to convert this string into an object which you could[/color]
      > access[color=green]
      > > like _firstname.text or _firstname.inne rhtml, any thing to being able to[/color]
      > set[color=green]
      > > the value would be great.
      > >
      > > Is there anyone who knows about an article or has an idea how to go[/color][/color]
      about[color=blue][color=green]
      > > doing this??
      > >
      > > Thanks,
      > >
      > > Wouter[/color]
      > You can put a placeholder (say it is called plc1) on a page and then in[/color]
      code[color=blue]
      > do the following
      > plc1.controls.a dd(New literalcontrol( yourhtmltext))
      >
      > Then on postback get the request.form("_ firstname") . Take the runat out[/color]
      of[color=blue]
      > the hmtltext
      >
      >[/color]


      Comment

      • John Saunders

        #4
        Re: Converting html string to object

        "Wouter vanEck" <wouter.vaneck@ smart-quotes.com> wrote in message
        news:uPu7bVO9EH A.2196@TK2MSFTN GP11.phx.gbl...[color=blue]
        > Hi,
        >
        > I need to find a way to read a html type string from a database and add it
        > to a placeholder control on the page and then I need to be able to
        > populate
        > the fields that were in that html string at run time.
        >
        > The html string may look like this "<table><tr><td >First
        > Name</td><td><input
        > name=_firstname runat=server id=_firstname ....></td></tr></table>"
        >
        > Is there a way to convert this string into an object which you could
        > access
        > like _firstname.text or _firstname.inne rhtml, any thing to being able to
        > set
        > the value would be great.
        >
        > Is there anyone who knows about an article or has an idea how to go about
        > doing this??[/color]

        You can't do this directly. If you can turn the database contents into a
        user control (.ascx file) on disk, then you can load it with LoadControl.

        Other than that, you'll have to parse the HTML string by yourself, using
        regular expressions or something.

        This appears to have been designed on the assumption that you can turn a
        string into a set of server-side controls. If this turns out not to be the
        case, and if you can't do the user control trick, then perhaps you could
        change design a bit. If the string in the database were a bit easier to
        parse for "fields", you'd have better luck with it. For instance, it could
        contain strings like %fieldName%. That's pretty easy to parse for. It's a
        lot easier to parse for than runat="server" id="_firstname" .

        John Saunders


        Comment

        • Wouter vanEck

          #5
          Re: Converting html string to object

          Hi John,

          It is not the answer I was hoping for, I am currently trying to work with
          rendering the string to the page.. same result unless I am doing it wrong.

          Wouter

          "John Saunders" <johnwsaundersi ii at hotmail.com> wrote in message
          news:OtPFNhO9EH A.1524@TK2MSFTN GP09.phx.gbl...[color=blue]
          > "Wouter vanEck" <wouter.vaneck@ smart-quotes.com> wrote in message
          > news:uPu7bVO9EH A.2196@TK2MSFTN GP11.phx.gbl...[color=green]
          > > Hi,
          > >
          > > I need to find a way to read a html type string from a database and add[/color][/color]
          it[color=blue][color=green]
          > > to a placeholder control on the page and then I need to be able to
          > > populate
          > > the fields that were in that html string at run time.
          > >
          > > The html string may look like this "<table><tr><td >First
          > > Name</td><td><input
          > > name=_firstname runat=server id=_firstname ....></td></tr></table>"
          > >
          > > Is there a way to convert this string into an object which you could
          > > access
          > > like _firstname.text or _firstname.inne rhtml, any thing to being able to
          > > set
          > > the value would be great.
          > >
          > > Is there anyone who knows about an article or has an idea how to go[/color][/color]
          about[color=blue][color=green]
          > > doing this??[/color]
          >
          > You can't do this directly. If you can turn the database contents into a
          > user control (.ascx file) on disk, then you can load it with LoadControl.
          >
          > Other than that, you'll have to parse the HTML string by yourself, using
          > regular expressions or something.
          >
          > This appears to have been designed on the assumption that you can turn a
          > string into a set of server-side controls. If this turns out not to be the
          > case, and if you can't do the user control trick, then perhaps you could
          > change design a bit. If the string in the database were a bit easier to
          > parse for "fields", you'd have better luck with it. For instance, it could
          > contain strings like %fieldName%. That's pretty easy to parse for. It's a
          > lot easier to parse for than runat="server" id="_firstname" .
          >
          > John Saunders
          >
          >[/color]


          Comment

          • vMike

            #6
            Re: Converting html string to object


            "Wouter vanEck" <wouter.vaneck@ smart-quotes.com> wrote in message
            news:%23JMecdO9 EHA.3124@TK2MSF TNGP11.phx.gbl. ..[color=blue]
            > Hi,
            >
            > Thanks for your quick response but I was actually trying to push a value[/color]
            to[color=blue]
            > the field. The reading part is easy, just like you said, but I need to be
            > able to populate the field after a postback.
            >[/color]
            If that is you only option then you could probably override the render of
            the placeholder and do a some kind of string replace before output, but you
            might want to consider some other approach.


            Comment

            • John Saunders

              #7
              Re: Converting html string to object

              "Wouter vanEck" <wouter.vaneck@ smart-quotes.com> wrote in message
              news:ufnZkuO9EH A.3236@TK2MSFTN GP15.phx.gbl...[color=blue]
              > Hi John,
              >
              > It is not the answer I was hoping for, I am currently trying to work with
              > rendering the string to the page.. same result unless I am doing it wrong.[/color]

              Are you aware that the runat="server" in these controls is meaningless?

              John Saunders


              Comment

              • Wouter vanEck

                #8
                Re: Converting html string to object

                :-)

                Now I do...



                "John Saunders" <johnwsaundersi ii at hotmail.com> wrote in message
                news:OKP4c0O9EH A.3756@TK2MSFTN GP14.phx.gbl...[color=blue]
                > "Wouter vanEck" <wouter.vaneck@ smart-quotes.com> wrote in message
                > news:ufnZkuO9EH A.3236@TK2MSFTN GP15.phx.gbl...[color=green]
                > > Hi John,
                > >
                > > It is not the answer I was hoping for, I am currently trying to work[/color][/color]
                with[color=blue][color=green]
                > > rendering the string to the page.. same result unless I am doing it[/color][/color]
                wrong.[color=blue]
                >
                > Are you aware that the runat="server" in these controls is meaningless?
                >
                > John Saunders
                >
                >[/color]


                Comment

                • vMike

                  #9
                  Re: Converting html string to object


                  "Wouter vanEck" <wouter.vaneck@ smart-quotes.com> wrote in message
                  news:uPu7bVO9EH A.2196@TK2MSFTN GP11.phx.gbl...[color=blue]
                  > Hi,
                  >
                  > I need to find a way to read a html type string from a database and add it
                  > to a placeholder control on the page and then I need to be able to[/color]
                  populate[color=blue]
                  > the fields that were in that html string at run time.
                  >
                  > The html string may look like this "<table><tr><td >First[/color]
                  Name</td><td><input[color=blue]
                  > name=_firstname runat=server id=_firstname ....></td></tr></table>"
                  >
                  > Is there a way to convert this string into an object which you could[/color]
                  access[color=blue]
                  > like _firstname.text or _firstname.inne rhtml, any thing to being able to[/color]
                  set[color=blue]
                  > the value would be great.
                  >
                  > Is there anyone who knows about an article or has an idea how to go about
                  > doing this??
                  >
                  > Thanks,
                  >[/color]
                  Actual something like this might work for you. plc1 is a placeholder
                  control.


                  dim strtext as string = "<table><tr><td >First Name</td><td><input
                  runat='server' id='_firstname' ></td></tr></table>"
                  dim ctrl as control = parsecontrol(st rtext)
                  ctrl.id = "ctrl1"
                  dim ctrl2 as htmlinputcontro l = ctype(ctrl.cont rols(1),htmlcon trol)
                  ctrl2.value = "yourvaluef or input box"
                  plc1.controls.a dd(ctrl)


                  Comment

                  • Roger Helliwell

                    #10
                    Re: Converting html string to object

                    On Fri, 7 Jan 2005 11:18:14 -0700 in
                    microsoft.publi c.dotnet.framew ork.aspnet, "Wouter vanEck"
                    <wouter.vaneck@ smart-quotes.com> wrote:
                    [color=blue]
                    >Hi,
                    >
                    >I need to find a way to read a html type string from a database and add it
                    >to a placeholder control on the page and then I need to be able to populate
                    >the fields that were in that html string at run time.
                    >
                    >The html string may look like this "<table><tr><td >First Name</td><td><input
                    >name=_firstnam e runat=server id=_firstname ....></td></tr></table>"
                    >
                    >Is there a way to convert this string into an object which you could access
                    >like _firstname.text or _firstname.inne rhtml, any thing to being able to set
                    >the value would be great.
                    >
                    >Is there anyone who knows about an article or has an idea how to go about
                    >doing this??
                    >
                    >Thanks,
                    >
                    >Wouter
                    >[/color]

                    Hi Wouter,

                    Not sure off hand how to convert your string into an object, but you
                    can easily convert your string into a control like so:

                    string sSomeHtmlString = get string from database();
                    Control ctrl = Page.ParseContr ol(sSomeHtmlStr ing); // Create control
                    Form1.Controls. Add(ctrl); // Add control to the Form

                    During postbacks, using FindControl("_f irstname") to get at individual
                    values. Likewise you could also set each value as needed.

                    Hopefully this is what you're looking for.
                    Roger

                    Comment

                    • Wouter vanEck

                      #11
                      Re: Converting html string to object

                      Hi Roger,

                      Excellent!!! Works like a charm.

                      Wouter

                      "Roger Helliwell" <rhelliwell@tel us.net> wrote in message
                      news:tt3ut0tcd8 0pap4k9nvblmsga tcr6tpd01@4ax.c om...[color=blue]
                      > On Fri, 7 Jan 2005 11:18:14 -0700 in
                      > microsoft.publi c.dotnet.framew ork.aspnet, "Wouter vanEck"
                      > <wouter.vaneck@ smart-quotes.com> wrote:
                      >[color=green]
                      > >Hi,
                      > >
                      > >I need to find a way to read a html type string from a database and add[/color][/color]
                      it[color=blue][color=green]
                      > >to a placeholder control on the page and then I need to be able to[/color][/color]
                      populate[color=blue][color=green]
                      > >the fields that were in that html string at run time.
                      > >
                      > >The html string may look like this "<table><tr><td >First[/color][/color]
                      Name</td><td><input[color=blue][color=green]
                      > >name=_firstnam e runat=server id=_firstname ....></td></tr></table>"
                      > >
                      > >Is there a way to convert this string into an object which you could[/color][/color]
                      access[color=blue][color=green]
                      > >like _firstname.text or _firstname.inne rhtml, any thing to being able to[/color][/color]
                      set[color=blue][color=green]
                      > >the value would be great.
                      > >
                      > >Is there anyone who knows about an article or has an idea how to go about
                      > >doing this??
                      > >
                      > >Thanks,
                      > >
                      > >Wouter
                      > >[/color]
                      >
                      > Hi Wouter,
                      >
                      > Not sure off hand how to convert your string into an object, but you
                      > can easily convert your string into a control like so:
                      >
                      > string sSomeHtmlString = get string from database();
                      > Control ctrl = Page.ParseContr ol(sSomeHtmlStr ing); // Create control
                      > Form1.Controls. Add(ctrl); // Add control to the Form
                      >
                      > During postbacks, using FindControl("_f irstname") to get at individual
                      > values. Likewise you could also set each value as needed.
                      >
                      > Hopefully this is what you're looking for.
                      > Roger
                      >[/color]


                      Comment

                      Working...