Insert Server Control Into HTML String (via Literal) at runtime

G

Guadala Harry

In an ASCX, I have a Literal control into which I inject a [string of HTML]
at runtime.

litInjectedContent.Text = dataClass.GetHTMLSnippetFromDB(someID);

This works great as long as the [string of HTML] contains just client-side
HTML, CSS, etc.

What I want to do is somehow insert a *server control* into the [string of
HTML], then set the server control's properties at runtime.

Specifically: suppose the [string of HTML] is a simple and empty one-cell
HTML table: <table><tr><td></td></tr></table>

At runtime I'd like to be able to inject that string (the HTML table) into
the ASCX via the Literal control (litUserContent) - AND THEN insert another
Server control into the empty <TD></TD>. The "other server control" could be
anything with runat=server. e.g., a TextBox

Is this even possible? If so, how can I accomplish this?

FWIW: the [string of HTML] could contain some flag text that indicates the
location in the [string of HTML] into which the new "other server control"
is to be placed.

Thanks!
 
K

Karl Seguin

I don't think that's possible. You can't parse a string into server side
controls...there _might_ be a 3rd party control to do this, but I doubt it.
My guess is that if you need to do this, there's probably a better way.
PEople typically create things dynmaically via code such as:

HtmlTable table = new HtmlTable();
HtmlTableRow row = new HtmlTableRow();
Table.Controls.Add(row);
.....

obviously that won't work from a string such as
<table><tr><td></td></tr></table> as you'd have to parse that out....

Karl
 
G

Guadala Harry

<< My guess is that if you need to do this, there's probably a better way.Yes - I agree that typically there is probably a better way; but here's why
I don't see much of a way around this: What I have is a CMS that lets users
enter new content via a Rich Text editor. That editor outputs HTML which
gets inserted into a database. Later I'm injecting that HTML into a
templated ASP.NET page (actually into a User Control) -- and I'm injecting
it via the Literal as described in the OP. It is into the user-supplied HTML
that I want to imbed another Server control.

I really need to find a way to do this and I believe there might be - even
if it requires me reworking how my ASPX pages are constructed. So, if you or
others could hang in with me on this and provide additional possibilities
I'd be eternally greatful - whatever that's worth :)

So, what I'm currently doing is this:
1 -- I have an ASPX page that does little more than hold an HTML table that
is used for placement of four (4) User controls: one for the page's header,
another for the footer, another for the navigational menu, and one for the
content area.

2 -- At runtime, the ASPX loads the various User controls into their
locations via Placeholder controls.

3 -- The content area's ASCX's code-behind logic retrieves the user-supplied
HTML snippet from the DB and injects it into the correct location via the
Literal control.

It is into that HTML snippet that I want to insert an additional server
control and manipulate its properties server-side before sending the page
down to the client.

I really need to make this happen - even if I have to rework the app in
order to get this result.

Thanks!




Karl Seguin said:
I don't think that's possible. You can't parse a string into server side
controls...there _might_ be a 3rd party control to do this, but I doubt it.
My guess is that if you need to do this, there's probably a better way.
PEople typically create things dynmaically via code such as:

HtmlTable table = new HtmlTable();
HtmlTableRow row = new HtmlTableRow();
Table.Controls.Add(row);
....

obviously that won't work from a string such as
<table><tr><td></td></tr></table> as you'd have to parse that out....

Karl



--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)


Guadala Harry said:
In an ASCX, I have a Literal control into which I inject a [string of
HTML] at runtime.

litInjectedContent.Text = dataClass.GetHTMLSnippetFromDB(someID);

This works great as long as the [string of HTML] contains just
client-side HTML, CSS, etc.

What I want to do is somehow insert a *server control* into the [string
of HTML], then set the server control's properties at runtime.

Specifically: suppose the [string of HTML] is a simple and empty one-cell
HTML table: <table><tr><td></td></tr></table>

At runtime I'd like to be able to inject that string (the HTML table)
into the ASCX via the Literal control (litUserContent) - AND THEN insert
another Server control into the empty <TD></TD>. The "other server
control" could be anything with runat=server. e.g., a TextBox

Is this even possible? If so, how can I accomplish this?

FWIW: the [string of HTML] could contain some flag text that indicates
the location in the [string of HTML] into which the new "other server
control" is to be placed.

Thanks!
 
J

James Doughty

Instead of using a Litercontrol use a placeholder control and then when
your loading your data use the ParseControl method of the placeholder to
insert your html/server side controls.
 
K

Karl Seguin

Seems like I had a hard time posting that last night :)

James idea might be useful (to use ParseControl)...

Given an html string as follows:

"<table><tr><td>{button}</td></tr></table>"

where {button} is the location you want to insert an ASP.Net button (and
"{button}" is actually in the string), you could use regular expressions to
brake the string up so that you have the following three matches:

"<table><tr><td>"
"{button}"
"</td></tr></table>"

you could loop through the collection of matches


for each match in matches
dim control as Control
if match.startswith("{") and match.endswidth("}") then
if match == "{button"}then
control = new Button();
...
else if match == "{linkbutotn}" then
...
end if
else (match isn't {XXX}) then
control = new Literal()
ctype(control, Literal).Text = match (just make it equal to the
text)
end if
if not control is nothig then
myContentPlaceholder.Controls.Add(control)
end if
next


Does something like that make sense? Does it work in your case?

Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)


Guadala Harry said:
<< My guess is that if you need to do this, there's probably a better way.Yes - I agree that typically there is probably a better way; but here's
why I don't see much of a way around this: What I have is a CMS that lets
users enter new content via a Rich Text editor. That editor outputs HTML
which gets inserted into a database. Later I'm injecting that HTML into a
templated ASP.NET page (actually into a User Control) -- and I'm injecting
it via the Literal as described in the OP. It is into the user-supplied
HTML that I want to imbed another Server control.

I really need to find a way to do this and I believe there might be - even
if it requires me reworking how my ASPX pages are constructed. So, if you
or others could hang in with me on this and provide additional
possibilities I'd be eternally greatful - whatever that's worth :)

So, what I'm currently doing is this:
1 -- I have an ASPX page that does little more than hold an HTML table
that is used for placement of four (4) User controls: one for the page's
header, another for the footer, another for the navigational menu, and one
for the content area.

2 -- At runtime, the ASPX loads the various User controls into their
locations via Placeholder controls.

3 -- The content area's ASCX's code-behind logic retrieves the
user-supplied HTML snippet from the DB and injects it into the correct
location via the Literal control.

It is into that HTML snippet that I want to insert an additional server
control and manipulate its properties server-side before sending the page
down to the client.

I really need to make this happen - even if I have to rework the app in
order to get this result.

Thanks!




Karl Seguin said:
I don't think that's possible. You can't parse a string into server side
controls...there _might_ be a 3rd party control to do this, but I doubt
it. My guess is that if you need to do this, there's probably a better
way. PEople typically create things dynmaically via code such as:

HtmlTable table = new HtmlTable();
HtmlTableRow row = new HtmlTableRow();
Table.Controls.Add(row);
....

obviously that won't work from a string such as
<table><tr><td></td></tr></table> as you'd have to parse that out....

Karl



--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)


Guadala Harry said:
In an ASCX, I have a Literal control into which I inject a [string of
HTML] at runtime.

litInjectedContent.Text = dataClass.GetHTMLSnippetFromDB(someID);

This works great as long as the [string of HTML] contains just
client-side HTML, CSS, etc.

What I want to do is somehow insert a *server control* into the [string
of HTML], then set the server control's properties at runtime.

Specifically: suppose the [string of HTML] is a simple and empty
one-cell HTML table: <table><tr><td></td></tr></table>

At runtime I'd like to be able to inject that string (the HTML table)
into the ASCX via the Literal control (litUserContent) - AND THEN insert
another Server control into the empty <TD></TD>. The "other server
control" could be anything with runat=server. e.g., a TextBox

Is this even possible? If so, how can I accomplish this?

FWIW: the [string of HTML] could contain some flag text that indicates
the location in the [string of HTML] into which the new "other server
control" is to be placed.

Thanks!
 
G

Guadala Harry

YES! Thank you so much! You clearly understand my objectives. While I
haven't yet implemented it, I'm sure it will work.

-GH


Karl Seguin said:
Seems like I had a hard time posting that last night :)

James idea might be useful (to use ParseControl)...

Given an html string as follows:

"<table><tr><td>{button}</td></tr></table>"

where {button} is the location you want to insert an ASP.Net button (and
"{button}" is actually in the string), you could use regular expressions
to brake the string up so that you have the following three matches:

"<table><tr><td>"
"{button}"
"</td></tr></table>"

you could loop through the collection of matches


for each match in matches
dim control as Control
if match.startswith("{") and match.endswidth("}") then
if match == "{button"}then
control = new Button();
...
else if match == "{linkbutotn}" then
...
end if
else (match isn't {XXX}) then
control = new Literal()
ctype(control, Literal).Text = match (just make it equal to the
text)
end if
if not control is nothig then
myContentPlaceholder.Controls.Add(control)
end if
next


Does something like that make sense? Does it work in your case?

Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)


Guadala Harry said:
<< My guess is that if you need to do this, there's probably a better
way.Yes - I agree that typically there is probably a better way; but here's
why I don't see much of a way around this: What I have is a CMS that lets
users enter new content via a Rich Text editor. That editor outputs HTML
which gets inserted into a database. Later I'm injecting that HTML into a
templated ASP.NET page (actually into a User Control) -- and I'm
injecting it via the Literal as described in the OP. It is into the
user-supplied HTML that I want to imbed another Server control.

I really need to find a way to do this and I believe there might be -
even if it requires me reworking how my ASPX pages are constructed. So,
if you or others could hang in with me on this and provide additional
possibilities I'd be eternally greatful - whatever that's worth :)

So, what I'm currently doing is this:
1 -- I have an ASPX page that does little more than hold an HTML table
that is used for placement of four (4) User controls: one for the page's
header, another for the footer, another for the navigational menu, and
one for the content area.

2 -- At runtime, the ASPX loads the various User controls into their
locations via Placeholder controls.

3 -- The content area's ASCX's code-behind logic retrieves the
user-supplied HTML snippet from the DB and injects it into the correct
location via the Literal control.

It is into that HTML snippet that I want to insert an additional server
control and manipulate its properties server-side before sending the page
down to the client.

I really need to make this happen - even if I have to rework the app in
order to get this result.

Thanks!




Karl Seguin said:
I don't think that's possible. You can't parse a string into server side
controls...there _might_ be a 3rd party control to do this, but I doubt
it. My guess is that if you need to do this, there's probably a better
way. PEople typically create things dynmaically via code such as:

HtmlTable table = new HtmlTable();
HtmlTableRow row = new HtmlTableRow();
Table.Controls.Add(row);
....

obviously that won't work from a string such as
<table><tr><td></td></tr></table> as you'd have to parse that out....

Karl



--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)


In an ASCX, I have a Literal control into which I inject a [string of
HTML] at runtime.

litInjectedContent.Text = dataClass.GetHTMLSnippetFromDB(someID);

This works great as long as the [string of HTML] contains just
client-side HTML, CSS, etc.

What I want to do is somehow insert a *server control* into the [string
of HTML], then set the server control's properties at runtime.

Specifically: suppose the [string of HTML] is a simple and empty
one-cell HTML table: <table><tr><td></td></tr></table>

At runtime I'd like to be able to inject that string (the HTML table)
into the ASCX via the Literal control (litUserContent) - AND THEN
insert another Server control into the empty <TD></TD>. The "other
server control" could be anything with runat=server. e.g., a TextBox

Is this even possible? If so, how can I accomplish this?

FWIW: the [string of HTML] could contain some flag text that indicates
the location in the [string of HTML] into which the new "other server
control" is to be placed.

Thanks!
 
J

James Doughty

GH,

If you need help let me know, I wrote a CMS type app myself. Also doing
the regular expersion may work, but I implemented it by building the HTML
page and doing on a parsecontrol on the string. In the end you should be
able to paste the html into a page and the page work correctly.
If you user parsecontrol on the following, it will display a server side
button

<table><tr><td><asp:button .... /></td></tr></table>

James

YES! Thank you so much! You clearly understand my objectives. While I
haven't yet implemented it, I'm sure it will work.

-GH


"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
net> wrote in message news:%[email protected]...
Seems like I had a hard time posting that last night :)

James idea might be useful (to use ParseControl)...

Given an html string as follows:

"<table><tr><td>{button}</td></tr></table>"

where {button} is the location you want to insert an ASP.Net button
(and "{button}" is actually in the string), you could use regular
expressions to brake the string up so that you have the following
three matches:

"<table><tr><td>"
"{button}"
"</td></tr></table>"

you could loop through the collection of matches


for each match in matches
dim control as Control
if match.startswith("{") and match.endswidth("}") then
if match == "{button"}then
control = new Button();
...
else if match == "{linkbutotn}" then
...
end if
else (match isn't {XXX}) then
control = new Literal()
ctype(control, Literal).Text = match (just make it equal to
the
text)
end if
if not control is nothig then
myContentPlaceholder.Controls.Add(control)
end if
next


Does something like that make sense? Does it work in your case?

Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying) http://www.openmymind.net/faq.aspx - unofficial newsgroup
FAQ (more to come!)


Guadala Harry said:
<< My guess is that if you need to do this, there's probably a
better way.

Yes - I agree that typically there is probably a better way; but
here's why I don't see much of a way around this: What I have is a
CMS that lets users enter new content via a Rich Text editor. That
editor outputs HTML which gets inserted into a database. Later I'm
injecting that HTML into a templated ASP.NET page (actually into a
User Control) -- and I'm injecting it via the Literal as described
in the OP. It is into the user-supplied HTML that I want to imbed
another Server control.

I really need to find a way to do this and I believe there might be
- even if it requires me reworking how my ASPX pages are
constructed. So, if you or others could hang in with me on this and
provide additional possibilities I'd be eternally greatful -
whatever that's worth :)

So, what I'm currently doing is this:
1 -- I have an ASPX page that does little more than hold an HTML
table that is used for placement of four (4) User controls: one for
the page's header, another for the footer, another for the
navigational menu, and one for the content area.

2 -- At runtime, the ASPX loads the various User controls into their
locations via Placeholder controls.

3 -- The content area's ASCX's code-behind logic retrieves the
user-supplied HTML snippet from the DB and injects it into the
correct location via the Literal control.

It is into that HTML snippet that I want to insert an additional
server control and manipulate its properties server-side before
sending the page down to the client.

I really need to make this happen - even if I have to rework the app
in order to get this result.

Thanks!




"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
net> wrote in message
I don't think that's possible. You can't parse a string into server
side controls...there _might_ be a 3rd party control to do this, but
I doubt it. My guess is that if you need to do this, there's
probably a better way. PEople typically create things dynmaically
via code such as:

HtmlTable table = new HtmlTable();
HtmlTableRow row = new HtmlTableRow();
Table.Controls.Add(row);
....

obviously that won't work from a string such as
<table><tr><td></td></tr></table> as you'd have to parse that
out....

Karl



--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more
to come!)


In an ASCX, I have a Literal control into which I inject a [string
of HTML] at runtime.

litInjectedContent.Text =
dataClass.GetHTMLSnippetFromDB(someID);

This works great as long as the [string of HTML] contains just
client-side HTML, CSS, etc.

What I want to do is somehow insert a *server control* into the
[string of HTML], then set the server control's properties at
runtime.

Specifically: suppose the [string of HTML] is a simple and empty
one-cell HTML table: <table><tr><td></td></tr></table>

At runtime I'd like to be able to inject that string (the HTML
table) into the ASCX via the Literal control (litUserContent) -
AND THEN insert another Server control into the empty <TD></TD>.
The "other server control" could be anything with runat=server.
e.g., a TextBox

Is this even possible? If so, how can I accomplish this?

FWIW: the [string of HTML] could contain some flag text that
indicates the location in the [string of HTML] into which the new
"other server control" is to be placed.

Thanks!
 
G

Guadala Harry

Thanks James. I got it to work by doing the following:

ContentPlaceHolder.Controls.Add(litUserContent1);
ContentPlaceHolder.Controls.Add(myUserControl);
ContentPlaceHolder.Controls.Add(litUserContent2);


Basically I split the user-supplied HTML into two strings, then inject it
via Literal controls litUserContent1/2, with the server-side user control
getting added between.

It works - but if there is a better, more elegant, better performing, or
more easily maintained approach, I'd like to see it.

Thanks again for your feedback.

-GH



James Doughty said:
GH,

If you need help let me know, I wrote a CMS type app myself. Also doing
the regular expersion may work, but I implemented it by building the HTML
page and doing on a parsecontrol on the string. In the end you should be
able to paste the html into a page and the page work correctly.
If you user parsecontrol on the following, it will display a server side
button

<table><tr><td><asp:button .... /></td></tr></table>

James

YES! Thank you so much! You clearly understand my objectives. While I
haven't yet implemented it, I'm sure it will work.

-GH


"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
net> wrote in message news:%[email protected]...
Seems like I had a hard time posting that last night :)

James idea might be useful (to use ParseControl)...

Given an html string as follows:

"<table><tr><td>{button}</td></tr></table>"

where {button} is the location you want to insert an ASP.Net button
(and "{button}" is actually in the string), you could use regular
expressions to brake the string up so that you have the following
three matches:

"<table><tr><td>"
"{button}"
"</td></tr></table>"

you could loop through the collection of matches


for each match in matches
dim control as Control
if match.startswith("{") and match.endswidth("}") then
if match == "{button"}then
control = new Button();
...
else if match == "{linkbutotn}" then
...
end if
else (match isn't {XXX}) then
control = new Literal()
ctype(control, Literal).Text = match (just make it equal to
the
text)
end if
if not control is nothig then
myContentPlaceholder.Controls.Add(control)
end if
next


Does something like that make sense? Does it work in your case?

Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying) http://www.openmymind.net/faq.aspx - unofficial newsgroup
FAQ (more to come!)


<< My guess is that if you need to do this, there's probably a
better way.

Yes - I agree that typically there is probably a better way; but
here's why I don't see much of a way around this: What I have is a
CMS that lets users enter new content via a Rich Text editor. That
editor outputs HTML which gets inserted into a database. Later I'm
injecting that HTML into a templated ASP.NET page (actually into a
User Control) -- and I'm injecting it via the Literal as described
in the OP. It is into the user-supplied HTML that I want to imbed
another Server control.

I really need to find a way to do this and I believe there might be
- even if it requires me reworking how my ASPX pages are
constructed. So, if you or others could hang in with me on this and
provide additional possibilities I'd be eternally greatful -
whatever that's worth :)

So, what I'm currently doing is this:
1 -- I have an ASPX page that does little more than hold an HTML
table that is used for placement of four (4) User controls: one for
the page's header, another for the footer, another for the
navigational menu, and one for the content area.

2 -- At runtime, the ASPX loads the various User controls into their
locations via Placeholder controls.

3 -- The content area's ASCX's code-behind logic retrieves the
user-supplied HTML snippet from the DB and injects it into the
correct location via the Literal control.

It is into that HTML snippet that I want to insert an additional
server control and manipulate its properties server-side before
sending the page down to the client.

I really need to make this happen - even if I have to rework the app
in order to get this result.

Thanks!




"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
net> wrote in message
I don't think that's possible. You can't parse a string into server
side controls...there _might_ be a 3rd party control to do this, but
I doubt it. My guess is that if you need to do this, there's
probably a better way. PEople typically create things dynmaically
via code such as:

HtmlTable table = new HtmlTable();
HtmlTableRow row = new HtmlTableRow();
Table.Controls.Add(row);
....

obviously that won't work from a string such as
<table><tr><td></td></tr></table> as you'd have to parse that
out....

Karl



--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more
to come!)


In an ASCX, I have a Literal control into which I inject a [string
of HTML] at runtime.

litInjectedContent.Text =
dataClass.GetHTMLSnippetFromDB(someID);

This works great as long as the [string of HTML] contains just
client-side HTML, CSS, etc.

What I want to do is somehow insert a *server control* into the
[string of HTML], then set the server control's properties at
runtime.

Specifically: suppose the [string of HTML] is a simple and empty
one-cell HTML table: <table><tr><td></td></tr></table>

At runtime I'd like to be able to inject that string (the HTML
table) into the ASCX via the Literal control (litUserContent) -
AND THEN insert another Server control into the empty <TD></TD>.
The "other server control" could be anything with runat=server.
e.g., a TextBox

Is this even possible? If so, how can I accomplish this?

FWIW: the [string of HTML] could contain some flag text that
indicates the location in the [string of HTML] into which the new
"other server control" is to be placed.

Thanks!
 
J

James Doughty

I'm not sure why you splitting the users control into 2 pieces, but if
your smyUserControl is know you can add it to the page. I've not had a
real issue with speed but none of the page are very graphic intensive.

As far as elegance it all depends on your needs, I'm using a XML Document
to create part of the pages I generate, I have all the data/controls
stored in a database and I'm using a webservice to retrueve the html
page.(yes the webservice is slow on the intiall load of the page but I
like the fact I if I need to redeploy this piece the users will more than
likely never see a glith on the system)

I'm also curious what are you using as the HTML editor?

James Doughty

Thanks James. I got it to work by doing the following:

ContentPlaceHolder.Controls.Add(litUserContent1);
ContentPlaceHolder.Controls.Add(myUserControl);
ContentPlaceHolder.Controls.Add(litUserContent2);


Basically I split the user-supplied HTML into two strings, then inject
it via Literal controls litUserContent1/2, with the server-side user
control getting added between.

It works - but if there is a better, more elegant, better performing,
or more easily maintained approach, I'd like to see it.

Thanks again for your feedback.

-GH



James Doughty said:
GH,

If you need help let me know, I wrote a CMS type app myself. Also
doing the regular expersion may work, but I implemented it by
building the HTML page and doing on a parsecontrol on the string. In
the end you should be able to paste the html into a page and the page
work correctly. If you user parsecontrol on the following, it will
display a server side button

<table><tr><td><asp:button .... /></td></tr></table>

James

YES! Thank you so much! You clearly understand my objectives. While
I haven't yet implemented it, I'm sure it will work.

-GH


"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
net> wrote in message
Seems like I had a hard time posting that last night :)

James idea might be useful (to use ParseControl)...

Given an html string as follows:

"<table><tr><td>{button}</td></tr></table>"

where {button} is the location you want to insert an ASP.Net button
(and "{button}" is actually in the string), you could use regular
expressions to brake the string up so that you have the following
three matches:

"<table><tr><td>"
"{button}"
"</td></tr></table>"

you could loop through the collection of matches


for each match in matches
dim control as Control
if match.startswith("{") and match.endswidth("}") then
if match == "{button"}then
control = new Button();
...
else if match == "{linkbutotn}" then
...
end if
else (match isn't {XXX}) then
control = new Literal()
ctype(control, Literal).Text = match (just make it equal to
the
text)
end if
if not control is nothig then
myContentPlaceholder.Controls.Add(control)
end if
next


Does something like that make sense? Does it work in your case?

Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying) http://www.openmymind.net/faq.aspx - unofficial newsgroup
FAQ (more to come!)


<< My guess is that if you need to do this, there's probably a
better way.

Yes - I agree that typically there is probably a better way; but
here's why I don't see much of a way around this: What I have is a
CMS that lets users enter new content via a Rich Text editor. That
editor outputs HTML which gets inserted into a database. Later I'm
injecting that HTML into a templated ASP.NET page (actually into a
User Control) -- and I'm injecting it via the Literal as described
in the OP. It is into the user-supplied HTML that I want to imbed
another Server control.

I really need to find a way to do this and I believe there might
be - even if it requires me reworking how my ASPX pages are
constructed. So, if you or others could hang in with me on this
and provide additional possibilities I'd be eternally greatful -
whatever that's worth :)

So, what I'm currently doing is this:
1 -- I have an ASPX page that does little more than hold an HTML
table that is used for placement of four (4) User controls: one
for the page's header, another for the footer, another for the
navigational menu, and one for the content area.

2 -- At runtime, the ASPX loads the various User controls into
their locations via Placeholder controls.

3 -- The content area's ASCX's code-behind logic retrieves the
user-supplied HTML snippet from the DB and injects it into the
correct location via the Literal control.

It is into that HTML snippet that I want to insert an additional
server control and manipulate its properties server-side before
sending the page down to the client.

I really need to make this happen - even if I have to rework the
app in order to get this result.

Thanks!




"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
net> wrote in message
I don't think that's possible. You can't parse a string into
server side controls...there _might_ be a 3rd party control to do
this, but I doubt it. My guess is that if you need to do this,
there's probably a better way. PEople typically create things
dynmaically via code such as:

HtmlTable table = new HtmlTable();
HtmlTableRow row = new HtmlTableRow();
Table.Controls.Add(row);
....

obviously that won't work from a string such as
<table><tr><td></td></tr></table> as you'd have to parse that
out....

Karl



--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ
(more to come!)


In an ASCX, I have a Literal control into which I inject a
[string of HTML] at runtime.

litInjectedContent.Text =
dataClass.GetHTMLSnippetFromDB(someID);

This works great as long as the [string of HTML] contains just
client-side HTML, CSS, etc.

What I want to do is somehow insert a *server control* into the
[string of HTML], then set the server control's properties at
runtime.

Specifically: suppose the [string of HTML] is a simple and empty
one-cell HTML table: <table><tr><td></td></tr></table>

At runtime I'd like to be able to inject that string (the HTML
table) into the ASCX via the Literal control (litUserContent) -
AND THEN insert another Server control into the empty <TD></TD>.
The "other server control" could be anything with runat=server.
e.g., a TextBox

Is this even possible? If so, how can I accomplish this?

FWIW: the [string of HTML] could contain some flag text that
indicates the location in the [string of HTML] into which the
new "other server control" is to be placed.

Thanks!
 
G

Guadala Harry

<<I'm not sure why you splitting the users control into 2 pieces>>
Actually I have a number of user controls in play here, and none are getting
split, themselves. What IS getting split is some HTML text (supplied by the
user via a rich text editor) that gets injected into one of the user
controls; and it's getting split ONLY so I can insert another user control
in the middle of that HTML.
The end result of this is that the user can create some HTML content. They
can enter some special "flag text" that indicates where a content rotator
should go. The final result is that they get a content rotator in the middle
of their content - and they don't have to know how to create the content
rotator. All they have to do is know how to specify the special "flag text"
correctly and place it where they want it. FWIW: That content rotator is
contained within the user control that I'm injecting into the middle of the
HTML text.
Sample:
"<table><tr><td>{ContentRotatorHere}</td></tr></table>"
The user creates the above complete HTML string - which gets saved to a
database. This is a gross oversimplification of course. Then, when it's time
to display their content elsewhere in the app - I pull that HTML string out
of a database, split it into two strings - one before "{ContentRotatorHere}"
and the other for what comes after it; then I insert the two "HTML strings"
into a Placeholder control along with the user control that contains the
content rotator. I add the HTML via two Literal controls, and add the
content rotator's containing user control between them in the Placeholder
control. This all actually works! It's a lot going on - but with a healthy
dose of Caching runtime performance is great.

<<I'm also curious what are you using as the HTML editor>>
A heavily customized implementation of CuteEditor which you can see at
www.CuteSoft.net

-GH


James Doughty said:
I'm not sure why you splitting the users control into 2 pieces, but if
your smyUserControl is know you can add it to the page. I've not had a
real issue with speed but none of the page are very graphic intensive.

As far as elegance it all depends on your needs, I'm using a XML Document
to create part of the pages I generate, I have all the data/controls
stored in a database and I'm using a webservice to retrueve the html
page.(yes the webservice is slow on the intiall load of the page but I
like the fact I if I need to redeploy this piece the users will more than
likely never see a glith on the system)

I'm also curious what are you using as the HTML editor?

James Doughty

Thanks James. I got it to work by doing the following:

ContentPlaceHolder.Controls.Add(litUserContent1);
ContentPlaceHolder.Controls.Add(myUserControl);
ContentPlaceHolder.Controls.Add(litUserContent2);


Basically I split the user-supplied HTML into two strings, then inject
it via Literal controls litUserContent1/2, with the server-side user
control getting added between.

It works - but if there is a better, more elegant, better performing,
or more easily maintained approach, I'd like to see it.

Thanks again for your feedback.

-GH



James Doughty said:
GH,

If you need help let me know, I wrote a CMS type app myself. Also
doing the regular expersion may work, but I implemented it by
building the HTML page and doing on a parsecontrol on the string. In
the end you should be able to paste the html into a page and the page
work correctly. If you user parsecontrol on the following, it will
display a server side button

<table><tr><td><asp:button .... /></td></tr></table>

James


YES! Thank you so much! You clearly understand my objectives. While
I haven't yet implemented it, I'm sure it will work.

-GH


"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
net> wrote in message
Seems like I had a hard time posting that last night :)

James idea might be useful (to use ParseControl)...

Given an html string as follows:

"<table><tr><td>{button}</td></tr></table>"

where {button} is the location you want to insert an ASP.Net button
(and "{button}" is actually in the string), you could use regular
expressions to brake the string up so that you have the following
three matches:

"<table><tr><td>"
"{button}"
"</td></tr></table>"

you could loop through the collection of matches


for each match in matches
dim control as Control
if match.startswith("{") and match.endswidth("}") then
if match == "{button"}then
control = new Button();
...
else if match == "{linkbutotn}" then
...
end if
else (match isn't {XXX}) then
control = new Literal()
ctype(control, Literal).Text = match (just make it equal to
the
text)
end if
if not control is nothig then
myContentPlaceholder.Controls.Add(control)
end if
next


Does something like that make sense? Does it work in your case?

Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying) http://www.openmymind.net/faq.aspx - unofficial newsgroup
FAQ (more to come!)


<< My guess is that if you need to do this, there's probably a
better way.

Yes - I agree that typically there is probably a better way; but
here's why I don't see much of a way around this: What I have is a
CMS that lets users enter new content via a Rich Text editor. That
editor outputs HTML which gets inserted into a database. Later I'm
injecting that HTML into a templated ASP.NET page (actually into a
User Control) -- and I'm injecting it via the Literal as described
in the OP. It is into the user-supplied HTML that I want to imbed
another Server control.

I really need to find a way to do this and I believe there might
be - even if it requires me reworking how my ASPX pages are
constructed. So, if you or others could hang in with me on this
and provide additional possibilities I'd be eternally greatful -
whatever that's worth :)

So, what I'm currently doing is this:
1 -- I have an ASPX page that does little more than hold an HTML
table that is used for placement of four (4) User controls: one
for the page's header, another for the footer, another for the
navigational menu, and one for the content area.

2 -- At runtime, the ASPX loads the various User controls into
their locations via Placeholder controls.

3 -- The content area's ASCX's code-behind logic retrieves the
user-supplied HTML snippet from the DB and injects it into the
correct location via the Literal control.

It is into that HTML snippet that I want to insert an additional
server control and manipulate its properties server-side before
sending the page down to the client.

I really need to make this happen - even if I have to rework the
app in order to get this result.

Thanks!




"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
net> wrote in message
I don't think that's possible. You can't parse a string into
server side controls...there _might_ be a 3rd party control to do
this, but I doubt it. My guess is that if you need to do this,
there's probably a better way. PEople typically create things
dynmaically via code such as:

HtmlTable table = new HtmlTable();
HtmlTableRow row = new HtmlTableRow();
Table.Controls.Add(row);
....

obviously that won't work from a string such as
<table><tr><td></td></tr></table> as you'd have to parse that
out....

Karl



--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ
(more to come!)


In an ASCX, I have a Literal control into which I inject a
[string of HTML] at runtime.

litInjectedContent.Text =
dataClass.GetHTMLSnippetFromDB(someID);

This works great as long as the [string of HTML] contains just
client-side HTML, CSS, etc.

What I want to do is somehow insert a *server control* into the
[string of HTML], then set the server control's properties at
runtime.

Specifically: suppose the [string of HTML] is a simple and empty
one-cell HTML table: <table><tr><td></td></tr></table>

At runtime I'd like to be able to inject that string (the HTML
table) into the ASCX via the Literal control (litUserContent) -
AND THEN insert another Server control into the empty <TD></TD>.
The "other server control" could be anything with runat=server.
e.g., a TextBox

Is this even possible? If so, how can I accomplish this?

FWIW: the [string of HTML] could contain some flag text that
indicates the location in the [string of HTML] into which the
new "other server control" is to be placed.

Thanks!
 
J

James Doughty

Sounds like your well on your way, I can't think of anything else.

Good luck,
James
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top