By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,745 Members | 1,897 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,745 IT Pros & Developers. It's quick & easy.

Suppress viewstate __viewstate rendering

P: n/a
I have an ASP.NET page that my client wants to e-mail. So in IE we choose
File > Send > Page by E-mail, which opens up either Outlook or Outlook
Express with the HTML page content as the message body.

EXCEPT one nasty detail is that in the e-mail client, <input type="hidden">
elements are rendered as text boxes, which the __VIEWSTATE is one of, and so
the viewstate is displayed in a textbox at the top of the e-mail.

I've figured out some overrides and stuff to ensure that the textbox is
empty, so the HTML renders

<input type="hidden" name="__VIEWSTATE" value="">

but this still displays an empty TextBox.

Is there any way to prevent the HTML element from being written at all? I
found an interesting explanation of why it's hard at this address:
http://scottonwriting.net/sowblog/posts/1608.aspx

But couldn't translate that into a solution.

--
Jason
www.pettysconsulting.com

Nov 19 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a
Just a thought
Is there way to set style display as none for hidden variable ??

vinay

"Jason Pettys" wrote:
I have an ASP.NET page that my client wants to e-mail. So in IE we choose
File > Send > Page by E-mail, which opens up either Outlook or Outlook
Express with the HTML page content as the message body.

EXCEPT one nasty detail is that in the e-mail client, <input type="hidden">
elements are rendered as text boxes, which the __VIEWSTATE is one of, and so
the viewstate is displayed in a textbox at the top of the e-mail.

I've figured out some overrides and stuff to ensure that the textbox is
empty, so the HTML renders

<input type="hidden" name="__VIEWSTATE" value="">

but this still displays an empty TextBox.

Is there any way to prevent the HTML element from being written at all? I
found an interesting explanation of why it's hard at this address:
http://scottonwriting.net/sowblog/posts/1608.aspx

But couldn't translate that into a solution.

--
Jason
www.pettysconsulting.com

Nov 19 '05 #2

P: n/a
I tried your suggestion but it did not work. See
http://pettysconsulting.com/test.htm. It has this defined:

<style type="text/css">
input { font-family: Verdana; display: none; }
</style>

Neither type="text" nor type="hidden" elements are shown in the web page,
but both are shown in Outlook (with Verdana font).

"vinay" wrote:
Just a thought
Is there way to set style display as none for hidden variable ??

vinay

"Jason Pettys" wrote:
I have an ASP.NET page that my client wants to e-mail. So in IE we choose
File > Send > Page by E-mail, which opens up either Outlook or Outlook
Express with the HTML page content as the message body.

EXCEPT one nasty detail is that in the e-mail client, <input type="hidden">
elements are rendered as text boxes, which the __VIEWSTATE is one of, and so
the viewstate is displayed in a textbox at the top of the e-mail.

I've figured out some overrides and stuff to ensure that the textbox is
empty, so the HTML renders

<input type="hidden" name="__VIEWSTATE" value="">

but this still displays an empty TextBox.

Is there any way to prevent the HTML element from being written at all? I
found an interesting explanation of why it's hard at this address:
http://scottonwriting.net/sowblog/posts/1608.aspx

But couldn't translate that into a solution.

--
Jason
www.pettysconsulting.com

Nov 19 '05 #3

P: n/a
Have you considered a server side solution that generates an e-mail wth the
BodyFormat property of your MailMessage set to MailFormat.Html? Obviously I
am not familiar with your project but typically when someone wants to e-mail
a page, it's a report or flyer of some sort which is dynamically generated.

If this is the case, you may want to switch to a method that generates the
HTML and puts it in a PlaceHolder for the page output and can also be set as
the Body property of your MailMessage.

HTH

--
Dave Fancher
http://davefancher.blogspot.com
"Jason Pettys" <pe****@nospam.nospam> wrote in message
news:35**********************************@microsof t.com...
I have an ASP.NET page that my client wants to e-mail. So in IE we choose
File > Send > Page by E-mail, which opens up either Outlook or Outlook
Express with the HTML page content as the message body.

EXCEPT one nasty detail is that in the e-mail client, <input
type="hidden">
elements are rendered as text boxes, which the __VIEWSTATE is one of, and
so
the viewstate is displayed in a textbox at the top of the e-mail.

I've figured out some overrides and stuff to ensure that the textbox is
empty, so the HTML renders

<input type="hidden" name="__VIEWSTATE" value="">

but this still displays an empty TextBox.

Is there any way to prevent the HTML element from being written at all? I
found an interesting explanation of why it's hard at this address:
http://scottonwriting.net/sowblog/posts/1608.aspx

But couldn't translate that into a solution.

--
Jason
www.pettysconsulting.com

Nov 19 '05 #4

P: n/a
That may be an option but it will take a lot of effort compared with File >
Send > Page by E-mail. I don't know that the HTML of the page can be grabbed
into a string like you suggest because it's a bunch of ASP.NET controls that
make up a timesheet entry/report page. The timesheet entry page is also the
timesheet report page by means of polymorphism to generate the correct data
controls (eg, textbox or label) depending on whether the timesheet is
editable. This is really slick because there's only one place to make
changes when modifying what a timesheet is.

Is there a way to grab the HTML that an arbitrary ASP.NET page will
generate? I tried HtmlForm.InnerText and .InnerHtml but that throws an
HttpException: "Cannot get inner content of FormActiveJobs because the
contents are not literal." I think that's a short description of what I'm
trying to explain in the above paragraph.

I think to do what you suggest I'd have to write a brand new view on the
timesheet data that can just dump HTML as a string. But that introduces
duplication that will have ongoing maintenance costs. I'd rather find a way
to hack the __VIEWSTATE so it doesn't show up.

If you know of a way to grab the HTML an arbitrary ASP.NET page will
generate into a string or stream I'd like to know of it.

Jason

"Dave Fancher" wrote:
Have you considered a server side solution that generates an e-mail wth the
BodyFormat property of your MailMessage set to MailFormat.Html? Obviously I
am not familiar with your project but typically when someone wants to e-mail
a page, it's a report or flyer of some sort which is dynamically generated.

If this is the case, you may want to switch to a method that generates the
HTML and puts it in a PlaceHolder for the page output and can also be set as
the Body property of your MailMessage.

HTH

--
Dave Fancher
http://davefancher.blogspot.com
"Jason Pettys" <pe****@nospam.nospam> wrote in message
news:35**********************************@microsof t.com...
I have an ASP.NET page that my client wants to e-mail. So in IE we choose
File > Send > Page by E-mail, which opens up either Outlook or Outlook
Express with the HTML page content as the message body.

EXCEPT one nasty detail is that in the e-mail client, <input
type="hidden">
elements are rendered as text boxes, which the __VIEWSTATE is one of, and
so
the viewstate is displayed in a textbox at the top of the e-mail.

I've figured out some overrides and stuff to ensure that the textbox is
empty, so the HTML renders

<input type="hidden" name="__VIEWSTATE" value="">

but this still displays an empty TextBox.

Is there any way to prevent the HTML element from being written at all? I
found an interesting explanation of why it's hard at this address:
http://scottonwriting.net/sowblog/posts/1608.aspx

But couldn't translate that into a solution.

--
Jason
www.pettysconsulting.com


Nov 19 '05 #5

P: n/a
I was afraid you were going to say that ;) I'm not sure of a way to grab
the HTML before it has been rendered but since you may be able to get away
with a different type of client side solution.

On your read only view you could add a button to open a new window and
dynamically populate the contents with JavaScript. I have included some
sample code below. Basically, just wrap everything you want to include on
the page you want to e-mail in a <span> and dynamically write the contents
to the new window. If the areas you want to e-mail are non-linear you could
use the getElementsByTagName() or getElementsByName() functions instead.
You said that your client is using IE so this should work just fine. Keep
in mind that JavaScript must be enabled.

<script language="javascript">
function OpenEMailWindow() {
var newWindow = window.open("about:blank", "EMailWindow");
newWindow.document.write("<html><head><title>EMail Sample</title><link
rel=\"stylesheet\" href=\"styles\/default.css\"></head><body>");
newWindow.document.write(document.getElementById(" EMailableContent").innerHTML);
newWindow.document.write("</body></html>");
}
</script>
....
<span id="EMailableContent">
All of your e-mailable contents would go here. Clicking the button below
will copy <b>everything</b> in this block to be copied to the new window.
</span>
<input type="button" value="EMail Friendly" onclick="OpenEMailWindow();">
....

HTH
--
Dave Fancher
http://davefancher.blogspot.com
"Jason Pettys" <pe****@nospam.nospam> wrote in message
news:5A**********************************@microsof t.com...
That may be an option but it will take a lot of effort compared with File
>

Send > Page by E-mail. I don't know that the HTML of the page can be
grabbed
into a string like you suggest because it's a bunch of ASP.NET controls
that
make up a timesheet entry/report page. The timesheet entry page is also
the
timesheet report page by means of polymorphism to generate the correct
data
controls (eg, textbox or label) depending on whether the timesheet is
editable. This is really slick because there's only one place to make
changes when modifying what a timesheet is.

Is there a way to grab the HTML that an arbitrary ASP.NET page will
generate? I tried HtmlForm.InnerText and .InnerHtml but that throws an
HttpException: "Cannot get inner content of FormActiveJobs because the
contents are not literal." I think that's a short description of what I'm
trying to explain in the above paragraph.

I think to do what you suggest I'd have to write a brand new view on the
timesheet data that can just dump HTML as a string. But that introduces
duplication that will have ongoing maintenance costs. I'd rather find a
way
to hack the __VIEWSTATE so it doesn't show up.

If you know of a way to grab the HTML an arbitrary ASP.NET page will
generate into a string or stream I'd like to know of it.

Jason

"Dave Fancher" wrote:
Have you considered a server side solution that generates an e-mail wth
the
BodyFormat property of your MailMessage set to MailFormat.Html?
Obviously I
am not familiar with your project but typically when someone wants to
e-mail
a page, it's a report or flyer of some sort which is dynamically
generated.

If this is the case, you may want to switch to a method that generates
the
HTML and puts it in a PlaceHolder for the page output and can also be set
as
the Body property of your MailMessage.

HTH

--
Dave Fancher
http://davefancher.blogspot.com
"Jason Pettys" <pe****@nospam.nospam> wrote in message
news:35**********************************@microsof t.com...
>I have an ASP.NET page that my client wants to e-mail. So in IE we
>choose
> File > Send > Page by E-mail, which opens up either Outlook or Outlook
> Express with the HTML page content as the message body.
>
> EXCEPT one nasty detail is that in the e-mail client, <input
> type="hidden">
> elements are rendered as text boxes, which the __VIEWSTATE is one of,
> and
> so
> the viewstate is displayed in a textbox at the top of the e-mail.
>
> I've figured out some overrides and stuff to ensure that the textbox is
> empty, so the HTML renders
>
> <input type="hidden" name="__VIEWSTATE" value="">
>
> but this still displays an empty TextBox.
>
> Is there any way to prevent the HTML element from being written at all?
> I
> found an interesting explanation of why it's hard at this address:
> http://scottonwriting.net/sowblog/posts/1608.aspx
>
> But couldn't translate that into a solution.
>
> --
> Jason
> www.pettysconsulting.com
>


Nov 19 '05 #6

P: n/a
Hello Jason,

If you put an asp:Button on the page, and contain the content you wish to
have rendered in a panel, something like this will do the trick (Im using
this exact technique to email portions of a site):

StringBuilder sb = new StringBuilder();
using (StringWriter sw = new StringWriter(sb))
using (HtmlTextWriter writer = new Html32TextWriter(sw))
{
theContentPanel.RenderControl(writer);
}

// at this point sb.ToString() contains a string of everything in that panel.
You're free to send this off via email or whatever.

I hope this is what you were after.

--
Matt Berther
http://www.mattberther.com
That may be an option but it will take a lot of effort compared with
File >
Send>> Page by E-mail. I don't know that the HTML of the page can be
Send>> grabbed
Send>> into a string like you suggest because it's a bunch of ASP.NET
controls that make up a timesheet entry/report page. The timesheet
entry page is also the timesheet report page by means of polymorphism
to generate the correct data controls (eg, textbox or label)
depending on whether the timesheet is editable. This is really slick
because there's only one place to make changes when modifying what a
timesheet is.

Is there a way to grab the HTML that an arbitrary ASP.NET page will
generate? I tried HtmlForm.InnerText and .InnerHtml but that throws
an HttpException: "Cannot get inner content of FormActiveJobs because
the contents are not literal." I think that's a short description of
what I'm trying to explain in the above paragraph.

I think to do what you suggest I'd have to write a brand new view on
the timesheet data that can just dump HTML as a string. But that
introduces duplication that will have ongoing maintenance costs. I'd
rather find a way to hack the __VIEWSTATE so it doesn't show up.

If you know of a way to grab the HTML an arbitrary ASP.NET page will
generate into a string or stream I'd like to know of it.

Jason

"Dave Fancher" wrote:
Have you considered a server side solution that generates an e-mail
wth the BodyFormat property of your MailMessage set to
MailFormat.Html? Obviously I am not familiar with your project but
typically when someone wants to e-mail a page, it's a report or flyer
of some sort which is dynamically generated.

If this is the case, you may want to switch to a method that
generates the HTML and puts it in a PlaceHolder for the page output
and can also be set as the Body property of your MailMessage.

HTH

--
Dave Fancher
http://davefancher.blogspot.com
"Jason Pettys" <pe****@nospam.nospam> wrote in message
news:35**********************************@microsof t.com...
I have an ASP.NET page that my client wants to e-mail. So in IE we
choose File > Send > Page by E-mail, which opens up either Outlook
or Outlook Express with the HTML page content as the message body.

EXCEPT one nasty detail is that in the e-mail client, <input
type="hidden">
elements are rendered as text boxes, which the __VIEWSTATE is one
of, and
so
the viewstate is displayed in a textbox at the top of the e-mail.
I've figured out some overrides and stuff to ensure that the textbox
is empty, so the HTML renders

<input type="hidden" name="__VIEWSTATE" value="">

but this still displays an empty TextBox.

Is there any way to prevent the HTML element from being written at
all? I found an interesting explanation of why it's hard at this
address: http://scottonwriting.net/sowblog/posts/1608.aspx

But couldn't translate that into a solution.

--
Jason
www.pettysconsulting.com



Nov 19 '05 #7

P: n/a
The code below was a wild guess (a worth trying thing). It copies the
content properly but doesn't render the html in the mail message.

Sorry!
--
Dave Fancher
http://davefancher.blogspot.com
"Dave Fancher" <ei*****@comcast.net> wrote in message
news:mq********************@comcast.com...
I was afraid you were going to say that ;) I'm not sure of a way to grab
the HTML before it has been rendered but since you may be able to get away
with a different type of client side solution.

On your read only view you could add a button to open a new window and
dynamically populate the contents with JavaScript. I have included some
sample code below. Basically, just wrap everything you want to include on
the page you want to e-mail in a <span> and dynamically write the contents
to the new window. If the areas you want to e-mail are non-linear you
could use the getElementsByTagName() or getElementsByName() functions
instead. You said that your client is using IE so this should work just
fine. Keep in mind that JavaScript must be enabled.

<script language="javascript">
function OpenEMailWindow() {
var newWindow = window.open("about:blank", "EMailWindow");
newWindow.document.write("<html><head><title>EMail Sample</title><link
rel=\"stylesheet\" href=\"styles\/default.css\"></head><body>");

newWindow.document.write(document.getElementById(" EMailableContent").innerHTML);
newWindow.document.write("</body></html>");
}
</script>
...
<span id="EMailableContent">
All of your e-mailable contents would go here. Clicking the button below
will copy <b>everything</b> in this block to be copied to the new window.
</span>
<input type="button" value="EMail Friendly" onclick="OpenEMailWindow();">
...

HTH
--
Dave Fancher
http://davefancher.blogspot.com
"Jason Pettys" <pe****@nospam.nospam> wrote in message
news:5A**********************************@microsof t.com...
That may be an option but it will take a lot of effort compared with File
>

Send > Page by E-mail. I don't know that the HTML of the page can be
grabbed
into a string like you suggest because it's a bunch of ASP.NET controls
that
make up a timesheet entry/report page. The timesheet entry page is also
the
timesheet report page by means of polymorphism to generate the correct
data
controls (eg, textbox or label) depending on whether the timesheet is
editable. This is really slick because there's only one place to make
changes when modifying what a timesheet is.

Is there a way to grab the HTML that an arbitrary ASP.NET page will
generate? I tried HtmlForm.InnerText and .InnerHtml but that throws an
HttpException: "Cannot get inner content of FormActiveJobs because the
contents are not literal." I think that's a short description of what
I'm
trying to explain in the above paragraph.

I think to do what you suggest I'd have to write a brand new view on the
timesheet data that can just dump HTML as a string. But that introduces
duplication that will have ongoing maintenance costs. I'd rather find a
way
to hack the __VIEWSTATE so it doesn't show up.

If you know of a way to grab the HTML an arbitrary ASP.NET page will
generate into a string or stream I'd like to know of it.

Jason

"Dave Fancher" wrote:
Have you considered a server side solution that generates an e-mail wth
the
BodyFormat property of your MailMessage set to MailFormat.Html?
Obviously I
am not familiar with your project but typically when someone wants to
e-mail
a page, it's a report or flyer of some sort which is dynamically
generated.

If this is the case, you may want to switch to a method that generates
the
HTML and puts it in a PlaceHolder for the page output and can also be
set as
the Body property of your MailMessage.

HTH

--
Dave Fancher
http://davefancher.blogspot.com
"Jason Pettys" <pe****@nospam.nospam> wrote in message
news:35**********************************@microsof t.com...
>I have an ASP.NET page that my client wants to e-mail. So in IE we
>choose
> File > Send > Page by E-mail, which opens up either Outlook or Outlook
> Express with the HTML page content as the message body.
>
> EXCEPT one nasty detail is that in the e-mail client, <input
> type="hidden">
> elements are rendered as text boxes, which the __VIEWSTATE is one of,
> and
> so
> the viewstate is displayed in a textbox at the top of the e-mail.
>
> I've figured out some overrides and stuff to ensure that the textbox
> is
> empty, so the HTML renders
>
> <input type="hidden" name="__VIEWSTATE" value="">
>
> but this still displays an empty TextBox.
>
> Is there any way to prevent the HTML element from being written at
> all? I
> found an interesting explanation of why it's hard at this address:
> http://scottonwriting.net/sowblog/posts/1608.aspx
>
> But couldn't translate that into a solution.
>
> --
> Jason
> www.pettysconsulting.com
>


Nov 19 '05 #8

P: n/a
Hi Jason,

I think Matt's suggestion on using the STringBuilder and HtmlTextWriter to
intercept the asp.net server control's output html is reasonable. In fact,
we can use this means to also get the HtmlForm or other control's output
html in a stringbuilder. Then, we can do some modification as we want, such
as remove all the <input type="hidden" ..> element or replace them with
other elements in it..... After that, you can just insert the modified
html string into your email body.

If there is any other questions or concerns, please feel free to post here.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 19 '05 #9

P: n/a
Thanks Matt and Steven! That is doing the trick.

Jason

www.pettysconsulting.com

"Steven Cheng[MSFT]" wrote:
Hi Jason,

I think Matt's suggestion on using the STringBuilder and HtmlTextWriter to
intercept the asp.net server control's output html is reasonable. In fact,
we can use this means to also get the HtmlForm or other control's output
html in a stringbuilder. Then, we can do some modification as we want, such
as remove all the <input type="hidden" ..> element or replace them with
other elements in it..... After that, you can just insert the modified
html string into your email body.

If there is any other questions or concerns, please feel free to post here.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 19 '05 #10

P: n/a
You're welcome.

Have a good day!

Regards,

Steven Cheng
Microsoft Online Support

Nov 19 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.