Showing posts with label client. Show all posts
Showing posts with label client. Show all posts

Saturday, March 31, 2012

server side code access the text of <asp:label> changed by client-side javascript co

Is possible for server side code to access the text of <asp:label> changed
by client side javascript code?Yes, of course you can do it.

--
-Saravana
http://dotnetjunkies.com/WebLog/saravana/
www.ExtremeExperts.com

"nick" <nbdy9.removethis@.hotmail.com> wrote in message
news:%23UAnyAt4EHA.2600@.TK2MSFTNGP09.phx.gbl...
> Is possible for server side code to access the text of <asp:label> changed
> by client side javascript code?
No, you will need to double the new value into a hidden text field, or some
other postable field, and then look for the change of the text through the
Request.Forms["txtHidden1"] property on postback to determine if the text
has changed.

bill

"nick" <nbdy9.removethis@.hotmail.com> wrote in message
news:%23UAnyAt4EHA.2600@.TK2MSFTNGP09.phx.gbl...
> Is possible for server side code to access the text of <asp:label> changed
> by client side javascript code?
If you mean accessing the text via the label's Text property, the answer is
no.

You can pass the changed text to the server in one of the common ways of
passing values from client to server, for example in a hidden field.

Eliyahu

"nick" <nbdy9.removethis@.hotmail.com> wrote in message
news:%23UAnyAt4EHA.2600@.TK2MSFTNGP09.phx.gbl...
> Is possible for server side code to access the text of <asp:label> changed
> by client side javascript code?

server side code access the text of <asp:label> changed by client-side javascri

Is possible for server side code to access the text of <asp:label> changed
by client side javascript code?Yes, of course you can do it.
-Saravana
http://dotnetjunkies.com/WebLog/saravana/
www.ExtremeExperts.com
"nick" <nbdy9.removethis@.hotmail.com> wrote in message
news:%23UAnyAt4EHA.2600@.TK2MSFTNGP09.phx.gbl...
> Is possible for server side code to access the text of <asp:label> changed
> by client side javascript code?
>
No, you will need to double the new value into a hidden text field, or some
other postable field, and then look for the change of the text through the
Request.Forms["txtHidden1"] property on postback to determine if the text
has changed.
bill
"nick" <nbdy9.removethis@.hotmail.com> wrote in message
news:%23UAnyAt4EHA.2600@.TK2MSFTNGP09.phx.gbl...
> Is possible for server side code to access the text of <asp:label> changed
> by client side javascript code?
>
If you mean accessing the text via the label's Text property, the answer is
no.
You can pass the changed text to the server in one of the common ways of
passing values from client to server, for example in a hidden field.
Eliyahu
"nick" <nbdy9.removethis@.hotmail.com> wrote in message
news:%23UAnyAt4EHA.2600@.TK2MSFTNGP09.phx.gbl...
> Is possible for server side code to access the text of <asp:label> changed
> by client side javascript code?
>

Thursday, March 29, 2012

server side or client side page?

a page that contain a validation control and starting a storeProcedures when the user click on a button --is considered as a client side page or as a server side page?
it seems to me that in asp.net everthing is server side, where are the client side pages?
thanks

The sp is server side, but the validation can be on or the other, depending on how it's coded.
ASP.Net has it's validations, so it's server side when using them.
But you can also make validations via JavaScript, so that would be client side.
Zath


but the validation controls (like RequiredFiledValidator) is a client side validation...,isnt that right?

because i know that if any of the validators are found to be on error the submission of the form to the server is cancelled...
so is there something that is done on the client side in asp.net?
thanks for the help


ppl1 wrote:

but the validation controls (like RequiredFiledValidator) is a client side validation...,isnt that right?

because i know that if any of the validators are found to be on error the submission of the form to the server is cancelled...


Yes the RequiredFieldValidator does the client side validation

ppl1 wrote:


so is there something that is done on the client side in asp.net?
thanks for the help


You can do so many things on client side and you should do so many things on client side to minimize postbacks if possible. So what exactly is that you are asking. Usually you use javascript to do client side stuff..


ok...so lets go back to my first question-> a page that contain a validation control and starting a storeProcedures when the user click on a button --is considered as a client side page or as a server side page?

ppl1 wrote:

ok...so lets go back to my first question-> a page that contain a validation control and starting a storeProcedures when the user click on a button --is considered as a client side page or as a server side page?


A webpage physically is considered a client side output for the asp.net server side processing. Asp.net uses browser to show its output to the user in the form of a web page. So, a webpage is a client side entity. Server wouldnt know anything about it after it outputs the html into the browser. Now, when the user clicks on the button, the page gets postback to the server. In here there are several things that goes on. The event of user clicking the button will be a client side event, and the page postbacks and server does some processing in response to the user action, which is button click event.

ok thanks for the help
Hi ,
Answering your question, calling a Stored Procedure is a Server Side call.
A page can contain server as well as client side technologies.
Hope it helps
Shahram

server side or client side buttton

Hello again!!
my understanding of the principles of this stuff are a bit vague so i
apologise in advance - sort of thrown in at the deep end. Anyway - I
am working on a project at the minute and i have created a button
using the following code.
<asp:button id="Button1" onclick="upload" runat="server" Width="119px"
text="Upload"></asp:button>
this button calls and runs some code ie. sub upload - see below
Public Sub upload(ByVal s As Object, ByVal e As EventArgs)
i have created my own button in fireworks and want to insert it in my
code an call this function but it does not work - code below
<INPUT id="btn_EditImage" type="image" src="http://pics.10026.com/?src=Buttons/EditImage.gif"
onclick="upload" runat="server"></TD>.
i can change my button to a server control and call the function from
there but there is an issue with the arguments in the code. any ideas
appreciated .
CGcsgraham74@.hotmail.com (Colin Graham) wrote in
news:ee261922.0504191329.e596fac@.posting.google.com:

> i have created my own button in fireworks and want to insert it in my
> code an call this function but it does not work - code below
> <INPUT id="btn_EditImage" type="image" src="http://pics.10026.com/?src=Buttons/EditImage.gif"
> onclick="upload" runat="server"></TD>.
The onClick method is for Javascript functions - not server side functions.
Since you're using fireworks for your button (it's a graphic right?) use an
imageButton instead of a regular .NET button. That'll allow you to bind the
button to .NET functions.

> i can change my button to a server control and call the function from
> there but there is an issue with the arguments in the code. any ideas
> appreciated .
Lucas Tam (REMOVEnntp@.rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
[url]http://members.ebay.com/aboutme/spot18/[/url]
thanks lucas ive tried that and the button works fine unfortunately i
now get the following error
Parser Error Message: The base class includes the field 'button1', but
its type (System.Web.UI.WebControls.Button) is not compatible with the
type of control (System.Web.UI.WebControls.ImageButton).
does this mean i have to change my asp.net function'
any help appreciated
CG
csgraham74@.hotmail.com (Colin Graham) wrote in
news:ee261922.0504210327.5bf5452f@.posting.google.com:

> thanks lucas ive tried that and the button works fine unfortunately i
> now get the following error
> Parser Error Message: The base class includes the field 'button1', but
> its type (System.Web.UI.WebControls.Button) is not compatible with the
> type of control (System.Web.UI.WebControls.ImageButton).
> does this mean i have to change my asp.net function'
Check your codebehind... is button1 still declared as a
System.Web.UI.WebControls.Button not as a
System.Web.UI.WebControls.ImageButton? Make sure button one is declared as
a ImageButton.
Take a look at the "hidden" code VS.NET auto generates. Sometimes it
doesn't update the code properly.
Lucas Tam (REMOVEnntp@.rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
[url]http://members.ebay.com/aboutme/spot18/[/url]

server side or client side buttton

Hello again!!

my understanding of the principles of this stuff are a bit vague so i
apologise in advance - sort of thrown in at the deep end. Anyway - I
am working on a project at the minute and i have created a button
using the following code.

<asp:button id="Button1" onclick="upload" runat="server" Width="119px"
text="Upload"></asp:button
this button calls and runs some code ie. sub upload - see below

Public Sub upload(ByVal s As Object, ByVal e As EventArgs)

i have created my own button in fireworks and want to insert it in my
code an call this function but it does not work - code below
<INPUT id="btn_EditImage" type="image" src="http://pics.10026.com/?src=Buttons/EditImage.gif"
onclick="upload" runat="server"></TD>.

i can change my button to a server control and call the function from
there but there is an issue with the arguments in the code. any ideas
appreciated .

CGcsgraham74@.hotmail.com (Colin Graham) wrote in
news:ee261922.0504191329.e596fac@.posting.google.co m:

> i have created my own button in fireworks and want to insert it in my
> code an call this function but it does not work - code below
> <INPUT id="btn_EditImage" type="image" src="http://pics.10026.com/?src=Buttons/EditImage.gif"
> onclick="upload" runat="server"></TD>.

The onClick method is for Javascript functions - not server side functions.

Since you're using fireworks for your button (it's a graphic right?) use an
imageButton instead of a regular .NET button. That'll allow you to bind the
button to .NET functions.

> i can change my button to a server control and call the function from
> there but there is an issue with the arguments in the code. any ideas
> appreciated .

--
Lucas Tam (REMOVEnntp@.rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
thanks lucas ive tried that and the button works fine unfortunately i
now get the following error

Parser Error Message: The base class includes the field 'button1', but
its type (System.Web.UI.WebControls.Button) is not compatible with the
type of control (System.Web.UI.WebControls.ImageButton).

does this mean i have to change my asp.net function??

any help appreciated

CG
csgraham74@.hotmail.com (Colin Graham) wrote in
news:ee261922.0504210327.5bf5452f@.posting.google.c om:

> thanks lucas ive tried that and the button works fine unfortunately i
> now get the following error
> Parser Error Message: The base class includes the field 'button1', but
> its type (System.Web.UI.WebControls.Button) is not compatible with the
> type of control (System.Web.UI.WebControls.ImageButton).
> does this mean i have to change my asp.net function??

Check your codebehind... is button1 still declared as a
System.Web.UI.WebControls.Button not as a
System.Web.UI.WebControls.ImageButton? Make sure button one is declared as
a ImageButton.

Take a look at the "hidden" code VS.NET auto generates. Sometimes it
doesn't update the code properly.

--
Lucas Tam (REMOVEnntp@.rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/

Server Side or Client Side

Hi I'm a bit confused about this whole server side / client side thing. Are applets, embeded objects consider client side? If I have a form within my aspx page which connects to a database on the server side what is it considered? If I have some business logic written within a VB file when the client access the functions within that business logic (for example some kind of validation function) does the client browser actually downloads that VB file? Can someone suggest how to differentiate between client side and server side components within a asp.net based website?

Hi,

i can't understand your actual problem but i m just trying to solve your confusion bet. client side and server side.

Suppose u want to apply some business logic and for that u need some data from database side so 4 that u write your all calculation and your all business logic on databaase side to use some "stored procedure" or "triggers" it will give you fast access.

and Suppose u want to apply some business logic and for that u dont need some data from database side so 4 that u write your all calculation and your all business logic on "javascripts" so its totally on "client side scripting". and page doesnt need to go back on server.


Hi rjjctm,

If you go tohttp://www.webopedia.com type server-side

"Occurring on theserver side of aclient-server system. For example, on theWorld Wide Web,CGI scripts are server-side applications because they run on theWeb server. In contrast,JavaScript scripts are client-side because they are executed by yourbrowser (theclient).Java applets can be either server-side orclient-side depending on which computer (theserver or the client) executes them. "

In your case:

If I have a form within my aspx page which connects to a database on the server side what is it considered?

( SERVER-SIDE )

If I have some business logic written within a VB file when the client access the functions within that business logic (for example some kind of validation function) does the client browser actually downloads that VB file

( SERVER-SIDE )

------------

Simple Scenario:

You have an object called [ACCOUNT]:

ACCOUNT have 2 property, ACC_NO and ACC_LIMIT.

Given rules ACC_NO is unique and ACC_LIMIT cannot be greater than 5000.

*** To validate above ( remember, always client-side get executed first ):

1) We validate ACC_LIMIT using client-side ( javascript )

<script language="javascript">

function ValidateAccountLimit(value)

if ( value > 500)

{

alert("Account limit cannot be greater than 5000");

return false;

}

</script>

2) Validate ACC_NO using server-side (c#)

private bool IsAccountNoExisted(string sAccNo){DataSet ds = SqlHelper.ExecuteDataSet("Select * from Account where ACC_NO='" + sAccNo +"'");if ( ds !=null )if ( ds.table[0].Rows.count > 0 )return true;// return true where record foundreturn false;// return false record not existed}

Hope this is clear enough.


SERVER SIDE VS CLIENT SIDE

Simply put there are two distinct operations involved in displaying anyweb page to the visitor the first being server side operations and thesecond client side operations.

Server Side Operations
Server side operations are concernedwith the sending of the web page data from the server to the web pagevisitors browser. In the case of Static Web Pages the data is simplyserved immediately upon request for the data from the visitors browser.If the requested page is a Dynamic Web Page then any pre processing ofthe page is carried out and the output is then served to the visitor.

PHP and ASP(vbscript) are server side scripting languages thatare used to pre process pages and output HTML before the page is sentto the visitor. HTML is the language that the browser understands thattells it how to display the page.

Client Side Operations
Client side operations are performed on the visitors computer by the users Internet browser to display the web page as the data is received from the server.

HTML is interpreted as it is read by the browser resulting in thedisplay of the web page within the browser. Once the page has loadedHTML cannot be reprocessed without refreshing the page.

The visitors experience on the web page can however be enhanced bymeans of a client side scripting language, typically Javascript used inconjunction with dynamic html and cascading style sheets, which enableinteractive menu systems, hi-lighting effects, image effects, datamanipulation and many other actions to be performed on the page withoutreloading or refreshing the page.

The relationship between server side and client side operations can be illustrated by the following example.

Suppose you wanted to display the current time on a web page. You havea number of options, you have the choice of displaying the current timeaccording to the web server or the current time according to thevisitors computer.

If you want to use the server time then server side pre processing willbe required to determine the current time on the server and write it tothe output in html format before the page is sent to the visitor.

To use the visitors local time, the current time on thevisitors computer is used to determine the time and display it on thepage. Since Javascript is running on the client side the time can beupdated and displayed in real time on the page without having to reloador refresh the page.

This is not possible with server side scripting as the page needs to bere processed on the server to determine and output the new time and resend to the visitor in order for the new time to be displayed.

The server time could of course be written to the page as a Javascript variable which Javascript could then use to set a local page time variable which could then be used to keep time. However one must bear in mind that time would elapse between the server creating and writing output for the Javascript time variable and Javascript actually reading in the variable upon page loading. Also one must remember that the updating of the clock would still be performed as a client side Javascript operation.

Whether you choose to display the local time on the server sideor client side or any of the standard times such as GMT, PST, EST isirrelevant as both server and client operations use the respectivelocal time and the time zone where the server or client is located todetermine the time in the aforementioned standard times.

Although primarily a client side scripting language, Javascript does offer some server side functionality however server side scripting languages such as PHP and ASP are generally far better suited to performing server side operations.

hope this helps./.


Thanks all for the help I think I have a better understanding now, Both kaushalparik27 and d4dennis examples helped me realized with some operations you can implemented both on the server side or the client side (ValidateAccountLimit can be done both in a javascript on the client side or a c# or vb based file on the server side but with the later there is the extra hassle of transferring data back and forth). But some operations such as validating account existence have to be done on the server side. I guess you would want as much things executed on client side as possible to reduce load on the server side.
So I guess to put it simply to determine whether something is server side or clients side code we just have to see where it's executed. Typing the above sentence out suddenly make it so obviousBig Smile.

Server side preview of IE rendering...

I am writing an ASP.NET tool that will allow the client to create their own
online froms. ie the client can add tect boxes, text, drop downs,etc with
absolutely no technical skill what so ever. The form can then be deployed to
their intranet.
The form designer is somewhat WYSIWYG but it contains a heap of 'edit',
'delete' and reordering buttons that are not seen when the form is acutally
being used.
I would love to have a preview image of what the form will actually look
like when it has been rendered in IE and display it in the form designer.
Much like a the print preview in Word.
I figure that my server would need some component that would acutally render
the page in some invisible IE and then take a screen shot of the web page
and then return the image. The designer could then hyperlink to that image
so the use could see a preview.
Another option would be to have an embedded frame but to adjust its 'zoom'
to be very small. Unfortunately frames do not support such a mythical
'zoom' feature.
Does any one have any idea about how I might solve this problem?
The poor mans option is to have a Preview button in the designer that will
lauch a new browser window and display the form but I am trying to steer
away form this.
Regards
Dave AHi Dave,
If I understand you right, you want to show a preview of the form to your
user, right? How are you rendering the final HTML? Are you using ASP.NET
server controls? Or are you just rendering straight HTML? If you are just
rendering straight HTML, you can update a <div> tag or <asp:Label> control
with your final HTML. You can do this on the server-side by simply
instantiating a HtmlGenericControl for your div tag and updating its
InnerHtml property with your final HTML...i.e. something like this:
<div ID="PreviewPanel" runat="server">
</div>
And in your server code:
// optional, depending on if you are using ASP.NET 2.0 or not
public HtmlGenericControl PreviewPanel;
[C#]
string finalHtml = "..."; // set this to your application generates
PreviewPanel.InnerHtml = finalHtml;
Voila, you are now rendering the HTML on the page. Just make sure to do this
upon every refresh, i.e. after every time your client updates something on
the page.
If you want to do something more complicated, i.e. render the ASP.NET server
controls, let me know.
Joshua Mitts
joshrm@.msn.com
"Dave A" <dave@.sigmasolutionsdonotspamme.com.au> wrote in message
news:%23YRXaa23FHA.2424@.TK2MSFTNGP10.phx.gbl...
>I am writing an ASP.NET tool that will allow the client to create their own
>online froms. ie the client can add tect boxes, text, drop downs,etc with
>absolutely no technical skill what so ever. The form can then be deployed
>to their intranet.
> The form designer is somewhat WYSIWYG but it contains a heap of 'edit',
> 'delete' and reordering buttons that are not seen when the form is
> acutally being used.
> I would love to have a preview image of what the form will actually look
> like when it has been rendered in IE and display it in the form designer.
> Much like a the print preview in Word.
> I figure that my server would need some component that would acutally
> render the page in some invisible IE and then take a screen shot of the
> web page and then return the image. The designer could then hyperlink to
> that image so the use could see a preview.
> Another option would be to have an embedded frame but to adjust its 'zoom'
> to be very small. Unfortunately frames do not support such a mythical
> 'zoom' feature.
> Does any one have any idea about how I might solve this problem?
> The poor mans option is to have a Preview button in the designer that will
> lauch a new browser window and display the form but I am trying to steer
> away form this.
> Regards
> Dave A
>
Sorry - I should have been more clear. I want a thumbnail representation of
what the page will actually look like.
Regards
Dave
"Josh Mitts" <joshrm@.msn.com> wrote in message
news:eO%235Ps23FHA.3880@.TK2MSFTNGP12.phx.gbl...
> Hi Dave,
> If I understand you right, you want to show a preview of the form to your
> user, right? How are you rendering the final HTML? Are you using ASP.NET
> server controls? Or are you just rendering straight HTML? If you are just
> rendering straight HTML, you can update a <div> tag or <asp:Label> control
> with your final HTML. You can do this on the server-side by simply
> instantiating a HtmlGenericControl for your div tag and updating its
> InnerHtml property with your final HTML...i.e. something like this:
> <div ID="PreviewPanel" runat="server">
> </div>
> And in your server code:
> // optional, depending on if you are using ASP.NET 2.0 or not
> public HtmlGenericControl PreviewPanel;
> [C#]
> string finalHtml = "..."; // set this to your application generates
> PreviewPanel.InnerHtml = finalHtml;
> Voila, you are now rendering the HTML on the page. Just make sure to do
> this upon every refresh, i.e. after every time your client updates
> something on the page.
> If you want to do something more complicated, i.e. render the ASP.NET
> server controls, let me know.
> --
> Joshua Mitts
> joshrm@.msn.com
>
> "Dave A" <dave@.sigmasolutionsdonotspamme.com.au> wrote in message
> news:%23YRXaa23FHA.2424@.TK2MSFTNGP10.phx.gbl...
>
Here you go
Daniel Fisher(lennybacon)
http://www.lennybacon.com
using System;
using System.IO;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;
// Interop
using AxSHDocVw;
using mshtml;
using SHDocVw;
namespace StaticDust
{
/// <summary>
/// Converts HTML documents to PNG format.
/// </summary>
public class Html2Image : System.Windows.Forms.UserControl
{
private AxSHDocVw.AxWebBrowser m_IE;
private System.ComponentModel.Container m_Components = null;
#region Html2Image()
private Html2Image()
{
// setups our embedded ie control
InitializeComponent();
}
#endregion
#region Convert()
/// <summary>
/// Converts a HTML file to a PNG file(s).
/// </summary>
/// <param name="url">A string with the url of the HTML file that should
be converted.</param>
/// <param name="pageLength">A int with the heigth of the PNG file(s).
Use -1 to capture the full HTML file.</param>
/// <param name="outputDir">A <see cref="System.String">string</see> with
the path of the directory, where the PNG file(s) should be saved.</param>
/// <param name="outputFile">A <see cref="System.String">string</see> with
the name of the PNG file(s).</param>
/// <returns>An array with filenames of the created PNG file(s).</returns>
/// <remarks>This method converts a HTML file to PNG file(s).</remarks>
public static String[] Convert(string url, int pageLength, string
outputDir, string outputFile)
{
Html2Image _html2Image = new Html2Image();
_html2Image.CreateControl();
string[] _f = _html2Image.CreateFiles(url, pageLength, outputDir,
outputFile);
_html2Image.Dispose();
return _f;
}
#endregion
#region CreateFiles()
private string[] CreateFiles(string url, int pageLength, string outputDir,
string outputFile)
{
while(!m_IE.Created)
{
Application.DoEvents();
}
object _arg1 = 0;
object _arg2 = "";
object _arg3 = "";
object _arg4 = "";
m_IE.Navigate(url, ref _arg1, ref _arg2, ref _arg3, ref _arg4);
while(!this.m_DocComplete)
{
Application.DoEvents();
}
Application.DoEvents();
while(GetHtmlBody() == null)
{
Application.DoEvents();
}
Application.DoEvents();
m_DocComplete = false;
m_IE.Navigate(url, ref _arg1, ref _arg2, ref _arg3, ref _arg4);
while(!this.m_DocComplete)
{
Application.DoEvents();
}
Application.DoEvents();
while(GetHtmlBody() == null)
{
Application.DoEvents();
}
Application.DoEvents();
for(int i=0; i<2000000; i++)
{
Application.DoEvents();
}
m_DocComplete = false;
m_IE.Navigate(url, ref _arg1, ref _arg2, ref _arg3, ref _arg4);
while(!this.m_DocComplete)
{
Application.DoEvents();
}
Application.DoEvents();
for(int i=0; i<2000000; i++)
{
Application.DoEvents();
}
while(GetHtmlBody() == null)
{
Application.DoEvents();
}
Application.DoEvents();
Bitmap _htmlimage = CaptureImage();
if (_htmlimage!=null)
{
if(pageLength==-1)
{
pageLength = _htmlimage.Height;
}
Bitmap _pageBitmap = new Bitmap(_htmlimage.Width, pageLength);
Graphics _g = Graphics.FromImage(_pageBitmap);
int _p = (int)Math.Floor(_htmlimage.Height/pageLength);
if(_p*pageLength<_htmlimage.Height)
{
_p++;
}
string[] _files = new string[_p];
for (int i=0;i<_files.GetLength(0);i++)
{
_g.Clear(Color.White);
_g.DrawImage(_htmlimage, new Rectangle(0, 0, _pageBitmap.Width,
pageLength), new Rectangle(0, (i*pageLength), _pageBitmap.Width,
pageLength), GraphicsUnit.Pixel);
_files[i] = Path.Combine(outputDir, outputFile+i+".png");
_pageBitmap.Save(_files[i], ImageFormat.Png);
}
_htmlimage.Dispose();
_g.Dispose();
_pageBitmap.Dispose();
return _files;
}
return null;
}
#endregion
#region OnDocumentComplete()
private bool m_DocComplete = false;
private void OnDocumentComplete(object sender,
AxSHDocVw. DWebBrowserEvents2_DocumentCompleteEvent
e)
{
m_DocComplete = true;
}
#endregion
#region CaptureImage()
private Bitmap CaptureImage()
{
try
{
IHTMLElement2 _htmlBody2 = GetHtmlBody();
Application.DoEvents();
int _w = _htmlBody2.scrollWidth;
int _h = _htmlBody2.scrollHeight;
// Make our embedded ie control that size
if((m_IE.Height != _h + 30) || (m_IE.Width != _w + 30))
{
m_IE.Height = _h + 30;
m_IE.Width = _w + 30;
}
// Setup bitmap memory and wrap a DC around it
Bitmap _bitmap = new Bitmap(_w, _h, PixelFormat.Format24bppRgb);
Graphics _graphics = Graphics.FromImage(_bitmap);
IntPtr _memdc = _graphics.GetHdc();
IntPtr _hbitmap = _bitmap.GetHbitmap();
SelectObject(_memdc, _hbitmap);
// Tell ie to print into our dc/bitmap
// Use PrintWindow windows api
//
const uint PW_CLIENTONLY = 0x00000001;
//
bool _rv = PrintWindow(m_IE.Handle, _memdc, PW_CLIENTONLY);
// Send it a print msg + flags
const uint WM_PRINT = 0x0317;
// const uint WM_PRINTCLIENT = 0x0318;
// const uint PRF_CHECKVISIBLE = 0x00000001;
const uint PRF_NONCLIENT = 0x00000002;
const uint PRF_CLIENT = 0x00000004;
const uint PRF_ERASEBKGND = 0x00000008;
const uint PRF_CHILDREN = 0x00000010;
const uint PRF_OWNED = 0x00000020;
int _err = SendMessage(m_IE.Handle, WM_PRINT, (uint)_memdc, (uint)
(PRF_CLIENT | PRF_NONCLIENT | PRF_OWNED | PRF_CHILDREN | PRF_ERASEBKGND));
// Save image
Bitmap _bitmap2 = Bitmap.FromHbitmap(_hbitmap);
// Cleanup
DeleteObject(_hbitmap);
_graphics.ReleaseHdc(_memdc);
_graphics.Dispose();
_bitmap.Dispose();
return _bitmap2;
}
catch(Exception ex)
{
System.Console.WriteLine("Exception: " + ex.Message + "\n");
System.Console.WriteLine(" source: " + ex.Source + "\n");
System.Console.WriteLine(" stacktrace:" + ex.StackTrace + "\n");
throw;
}
}
#endregion
#region Dispose()
/// <summary>
/// Releases the unmanaged resources used by the Control and its child
controls and optionally releases the managed resources.
/// </summary>
/// <param name="disposing"><b>true</b> to release both managed and
unmanaged resources; <b>false</b> to release only unmanaged resources.
</param>
/// <remarks>
/// This method is called by the public Dispose() method and the Finalize
method. <b>Dispose()</b>
/// invokes the protected <b>Dispose(Boolean)</b> method with
/// the <i>disposing</i> parameter set to <b>true</b>. <b>Finalize</b>
invokes <b>Dispose</b> with <i>disposing</i> set to <b>false</b>.
/// <br/>When the <i>disposing</i> parameter is <b>true</b>, this method
releases all resources held by any managed
/// objects that this Control and its child controls reference. This
method invokes the <b>Dispose()</b>
/// method of each referenced object.
/// <br/><b>Notes to Inheritors:</b> <b>Dispose</b> can be called
multiple times by other objects. When overriding
/// <b>Dispose(Boolean)</b>, be careful not to reference objects that have
been previously disposed of in
/// an earlier call to <b>Dispose</b>.
/// </remarks>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(m_Components != null)
{
m_Components.Dispose();
}
}
base.Dispose( disposing );
}
#endregion
#region InitializeComponent()
private void InitializeComponent()
{
System.Resources.ResourceManager _resources = new
System.Resources.ResourceManager(typeof(Html2Image));
this.m_IE = new AxSHDocVw.AxWebBrowser();
((System.ComponentModel.ISupportInitialize)(this.m_IE)).BeginInit();
this.SuspendLayout();
//
// m_IE
//
this.m_IE.Enabled = true;
this.m_IE.Location = new System.Drawing.Point(0, 0);
//this.m_IE.OcxState =
((System.Windows.Forms.AxHost.State)(resources.GetObject("m_IE.OcxState")));
this.m_IE.Size = new System.Drawing.Size(804, 580);
this.m_IE.TabIndex = 7;
this.m_IE.DocumentComplete += new
AxSHDocVw. DWebBrowserEvents2_DocumentCompleteEvent
Handler(this.OnDocumentCom
plete);
//
// Html2Image
//
this.Controls.AddRange(new System.Windows.Forms.Control[] { this.m_IE});
this.Size = new System.Drawing.Size(292, 266);
((System.ComponentModel.ISupportInitialize)(this.m_IE)).EndInit();
this.ResumeLayout(false);
}
#endregion
//IE InterOp
#region IHTMLElement2 GetHtmlBody()
private IHTMLElement2 GetHtmlBody()
{
IWebBrowser2 _wb2 = (IWebBrowser2) m_IE.GetOcx();
Application.DoEvents();
IHTMLDocument2 _htmlDocument2 = (IHTMLDocument2) _wb2.Document;
Application.DoEvents();
return (IHTMLElement2)_htmlDocument2.body;
}
#endregion
//Win32 InterOp
#region extern IntPtr SelectObject()
[DllImport("Gdi32.dll")]
private static extern IntPtr SelectObject(
IntPtr hdc, // handle to DC
IntPtr hgdiobj // handle to object
);
#endregion
#region extern bool DeleteObject()
[DllImport("Gdi32.dll")]
private static extern bool DeleteObject(
IntPtr hObject // handle to graphic object
);
#endregion
#region extern IntPtr CreateCompatibleDC()
[DllImport("Gdi32.dll")]
private static extern IntPtr CreateCompatibleDC(
IntPtr hdc // handle to DC
);
#endregion
#region extern bool DeleteDC()
[DllImport("Gdi32.dll")]
private static extern bool DeleteDC(
IntPtr hdc // handle to DC
);
#endregion
#region extern bool PrintWindow()
[DllImport("User32.dll")]
private static extern bool PrintWindow(
IntPtr hwnd, // Window to copy
IntPtr hdcBlt, // HDC to print into
uint nFlags // Optional flags // must contain PW_CLIENTONLY
);
#endregion
#region extern int SendMessage()
[DllImport("User32.dll")]
private static extern int SendMessage(
IntPtr hWnd, // handle to destination window
uint Msg, // message
uint wParam, // firstmessage parameter
uint lParam // second message parameter
);
#endregion
}
}
"Dave A" <dave@.sigmasolutionsdonotspamme.com.au> wrote in message
news:eIhiZOF4FHA.3628@.TK2MSFTNGP12.phx.gbl...
> Sorry - I should have been more clear. I want a thumbnail representation
> of what the page will actually look like.
> Regards
> Dave
> "Josh Mitts" <joshrm@.msn.com> wrote in message
> news:eO%235Ps23FHA.3880@.TK2MSFTNGP12.phx.gbl...
>
Holy crap! Well done man! I would never have worked this out and thought
that it was impossible. I am pleased that I asked.
Regards
Dave
"Daniel Fisher(lennybacon)" <info@.lennybacon.com> wrote in message
news:OHj8PjF4FHA.3628@.TK2MSFTNGP12.phx.gbl...
> Here you go
> --
> Daniel Fisher(lennybacon)
> http://www.lennybacon.com
> using System;
> using System.IO;
> using System.Collections;
> using System.ComponentModel;
> using System.Drawing;
> using System.Data;
> using System.Windows.Forms;
> using System.Drawing.Imaging;
> using System.Runtime.InteropServices;
> // Interop
> using AxSHDocVw;
> using mshtml;
> using SHDocVw;
> namespace StaticDust
> {
> /// <summary>
> /// Converts HTML documents to PNG format.
> /// </summary>
> public class Html2Image : System.Windows.Forms.UserControl
> {
> private AxSHDocVw.AxWebBrowser m_IE;
> private System.ComponentModel.Container m_Components = null;
> #region Html2Image()
> private Html2Image()
> {
> // setups our embedded ie control
> InitializeComponent();
> }
> #endregion
> #region Convert()
> /// <summary>
> /// Converts a HTML file to a PNG file(s).
> /// </summary>
> /// <param name="url">A string with the url of the HTML file that should
> be converted.</param>
> /// <param name="pageLength">A int with the heigth of the PNG file(s).
> Use -1 to capture the full HTML file.</param>
> /// <param name="outputDir">A <see cref="System.String">string</see> with
> the path of the directory, where the PNG file(s) should be saved.</param>
> /// <param name="outputFile">A <see cref="System.String">string</see>
> with the name of the PNG file(s).</param>
> /// <returns>An array with filenames of the created PNG
> file(s).</returns>
> /// <remarks>This method converts a HTML file to PNG file(s).</remarks>
> public static String[] Convert(string url, int pageLength, string
> outputDir, string outputFile)
> {
> Html2Image _html2Image = new Html2Image();
> _html2Image.CreateControl();
> string[] _f = _html2Image.CreateFiles(url, pageLength, outputDir,
> outputFile);
> _html2Image.Dispose();
> return _f;
> }
> #endregion
> #region CreateFiles()
> private string[] CreateFiles(string url, int pageLength, string
> outputDir, string outputFile)
> {
> while(!m_IE.Created)
> {
> Application.DoEvents();
> }
> object _arg1 = 0;
> object _arg2 = "";
> object _arg3 = "";
> object _arg4 = "";
> m_IE.Navigate(url, ref _arg1, ref _arg2, ref _arg3, ref _arg4);
> while(!this.m_DocComplete)
> {
> Application.DoEvents();
> }
> Application.DoEvents();
> while(GetHtmlBody() == null)
> {
> Application.DoEvents();
> }
> Application.DoEvents();
> m_DocComplete = false;
> m_IE.Navigate(url, ref _arg1, ref _arg2, ref _arg3, ref _arg4);
> while(!this.m_DocComplete)
> {
> Application.DoEvents();
> }
> Application.DoEvents();
> while(GetHtmlBody() == null)
> {
> Application.DoEvents();
> }
> Application.DoEvents();
> for(int i=0; i<2000000; i++)
> {
> Application.DoEvents();
> }
> m_DocComplete = false;
> m_IE.Navigate(url, ref _arg1, ref _arg2, ref _arg3, ref _arg4);
> while(!this.m_DocComplete)
> {
> Application.DoEvents();
> }
> Application.DoEvents();
> for(int i=0; i<2000000; i++)
> {
> Application.DoEvents();
> }
> while(GetHtmlBody() == null)
> {
> Application.DoEvents();
> }
> Application.DoEvents();
>
> Bitmap _htmlimage = CaptureImage();
> if (_htmlimage!=null)
> {
> if(pageLength==-1)
> {
> pageLength = _htmlimage.Height;
> }
> Bitmap _pageBitmap = new Bitmap(_htmlimage.Width, pageLength);
> Graphics _g = Graphics.FromImage(_pageBitmap);
> int _p = (int)Math.Floor(_htmlimage.Height/pageLength);
> if(_p*pageLength<_htmlimage.Height)
> {
> _p++;
> }
> string[] _files = new string[_p];
> for (int i=0;i<_files.GetLength(0);i++)
> {
> _g.Clear(Color.White);
> _g.DrawImage(_htmlimage, new Rectangle(0, 0, _pageBitmap.Width,
> pageLength), new Rectangle(0, (i*pageLength), _pageBitmap.Width,
> pageLength), GraphicsUnit.Pixel);
> _files[i] = Path.Combine(outputDir, outputFile+i+".png");
> _pageBitmap.Save(_files[i], ImageFormat.Png);
> }
> _htmlimage.Dispose();
> _g.Dispose();
> _pageBitmap.Dispose();
> return _files;
> }
> return null;
> }
> #endregion
> #region OnDocumentComplete()
> private bool m_DocComplete = false;
> private void OnDocumentComplete(object sender,
> AxSHDocVw. DWebBrowserEvents2_DocumentCompleteEvent
e)
> {
> m_DocComplete = true;
> }
> #endregion
>
> #region CaptureImage()
> private Bitmap CaptureImage()
> {
> try
> {
> IHTMLElement2 _htmlBody2 = GetHtmlBody();
> Application.DoEvents();
> int _w = _htmlBody2.scrollWidth;
> int _h = _htmlBody2.scrollHeight;
> // Make our embedded ie control that size
> if((m_IE.Height != _h + 30) || (m_IE.Width != _w + 30))
> {
> m_IE.Height = _h + 30;
> m_IE.Width = _w + 30;
> }
> // Setup bitmap memory and wrap a DC around it
> Bitmap _bitmap = new Bitmap(_w, _h, PixelFormat.Format24bppRgb);
> Graphics _graphics = Graphics.FromImage(_bitmap);
> IntPtr _memdc = _graphics.GetHdc();
> IntPtr _hbitmap = _bitmap.GetHbitmap();
> SelectObject(_memdc, _hbitmap);
> // Tell ie to print into our dc/bitmap
> // Use PrintWindow windows api
> //
> const uint PW_CLIENTONLY = 0x00000001;
> //
> bool _rv = PrintWindow(m_IE.Handle, _memdc, PW_CLIENTONLY);
> // Send it a print msg + flags
> const uint WM_PRINT = 0x0317;
> // const uint WM_PRINTCLIENT = 0x0318;
> // const uint PRF_CHECKVISIBLE = 0x00000001;
> const uint PRF_NONCLIENT = 0x00000002;
> const uint PRF_CLIENT = 0x00000004;
> const uint PRF_ERASEBKGND = 0x00000008;
> const uint PRF_CHILDREN = 0x00000010;
> const uint PRF_OWNED = 0x00000020;
> int _err = SendMessage(m_IE.Handle, WM_PRINT, (uint)_memdc, (uint)
> (PRF_CLIENT | PRF_NONCLIENT | PRF_OWNED | PRF_CHILDREN | PRF_ERASEBKGND));
> // Save image
> Bitmap _bitmap2 = Bitmap.FromHbitmap(_hbitmap);
> // Cleanup
> DeleteObject(_hbitmap);
> _graphics.ReleaseHdc(_memdc);
> _graphics.Dispose();
> _bitmap.Dispose();
> return _bitmap2;
> }
> catch(Exception ex)
> {
> System.Console.WriteLine("Exception: " + ex.Message + "\n");
> System.Console.WriteLine(" source: " + ex.Source + "\n");
> System.Console.WriteLine(" stacktrace:" + ex.StackTrace + "\n");
> throw;
> }
> }
> #endregion
>
> #region Dispose()
> /// <summary>
> /// Releases the unmanaged resources used by the Control and its child
> controls and optionally releases the managed resources.
> /// </summary>
> /// <param name="disposing"><b>true</b> to release both managed and
> unmanaged resources; <b>false</b> to release only unmanaged resources.
> </param>
> /// <remarks>
> /// This method is called by the public Dispose() method and the Finalize
> method. <b>Dispose()</b>
> /// invokes the protected <b>Dispose(Boolean)</b> method with
> /// the <i>disposing</i> parameter set to <b>true</b>. <b>Finalize</b>
> invokes <b>Dispose</b> with <i>disposing</i> set to <b>false</b>.
> /// <br/>When the <i>disposing</i> parameter is <b>true</b>, this method
> releases all resources held by any managed
> /// objects that this Control and its child controls reference. This
> method invokes the <b>Dispose()</b>
> /// method of each referenced object.
> /// <br/><b>Notes to Inheritors:</b> <b>Dispose</b> can be called
> multiple times by other objects. When overriding
> /// <b>Dispose(Boolean)</b>, be careful not to reference objects that
> have been previously disposed of in
> /// an earlier call to <b>Dispose</b>.
> /// </remarks>
> protected override void Dispose( bool disposing )
> {
> if( disposing )
> {
> if(m_Components != null)
> {
> m_Components.Dispose();
> }
> }
> base.Dispose( disposing );
> }
> #endregion
> #region InitializeComponent()
> private void InitializeComponent()
> {
> System.Resources.ResourceManager _resources = new
> System.Resources.ResourceManager(typeof(Html2Image));
> this.m_IE = new AxSHDocVw.AxWebBrowser();
> ((System.ComponentModel.ISupportInitialize)(this.m_IE)).BeginInit();
> this.SuspendLayout();
> //
> // m_IE
> //
> this.m_IE.Enabled = true;
> this.m_IE.Location = new System.Drawing.Point(0, 0);
> //this.m_IE.OcxState =
> ((System.Windows.Forms.AxHost.State)(resources.GetObject("m_IE.OcxState"))
);
> this.m_IE.Size = new System.Drawing.Size(804, 580);
> this.m_IE.TabIndex = 7;
> this.m_IE.DocumentComplete += new
> AxSHDocVw. DWebBrowserEvents2_DocumentCompleteEvent
Handler(this.OnDocumentC
omplete);
> //
> // Html2Image
> //
> this.Controls.AddRange(new System.Windows.Forms.Control[] { this.m_IE});
> this.Size = new System.Drawing.Size(292, 266);
> ((System.ComponentModel.ISupportInitialize)(this.m_IE)).EndInit();
> this.ResumeLayout(false);
> }
> #endregion
>
> //IE InterOp
> #region IHTMLElement2 GetHtmlBody()
> private IHTMLElement2 GetHtmlBody()
> {
> IWebBrowser2 _wb2 = (IWebBrowser2) m_IE.GetOcx();
> Application.DoEvents();
> IHTMLDocument2 _htmlDocument2 = (IHTMLDocument2) _wb2.Document;
> Application.DoEvents();
> return (IHTMLElement2)_htmlDocument2.body;
> }
> #endregion
>
> //Win32 InterOp
> #region extern IntPtr SelectObject()
> [DllImport("Gdi32.dll")]
> private static extern IntPtr SelectObject(
> IntPtr hdc, // handle to DC
> IntPtr hgdiobj // handle to object
> );
> #endregion
> #region extern bool DeleteObject()
> [DllImport("Gdi32.dll")]
> private static extern bool DeleteObject(
> IntPtr hObject // handle to graphic object
> );
> #endregion
> #region extern IntPtr CreateCompatibleDC()
> [DllImport("Gdi32.dll")]
> private static extern IntPtr CreateCompatibleDC(
> IntPtr hdc // handle to DC
> );
> #endregion
> #region extern bool DeleteDC()
> [DllImport("Gdi32.dll")]
> private static extern bool DeleteDC(
> IntPtr hdc // handle to DC
> );
> #endregion
> #region extern bool PrintWindow()
> [DllImport("User32.dll")]
> private static extern bool PrintWindow(
> IntPtr hwnd, // Window to copy
> IntPtr hdcBlt, // HDC to print into
> uint nFlags // Optional flags // must contain
> PW_CLIENTONLY
> );
> #endregion
> #region extern int SendMessage()
> [DllImport("User32.dll")]
> private static extern int SendMessage(
> IntPtr hWnd, // handle to destination window
> uint Msg, // message
> uint wParam, // firstmessage parameter
> uint lParam // second message parameter
> );
> #endregion
> }
> }
>
> "Dave A" <dave@.sigmasolutionsdonotspamme.com.au> wrote in message
> news:eIhiZOF4FHA.3628@.TK2MSFTNGP12.phx.gbl...
>
Will this work with .Net 2.0 ?
Do any special references need to be added to the project?
--Alex

Server side preview of IE rendering...

I am writing an ASP.NET tool that will allow the client to create their own
online froms. ie the client can add tect boxes, text, drop downs,etc with
absolutely no technical skill what so ever. The form can then be deployed to
their intranet.

The form designer is somewhat WYSIWYG but it contains a heap of 'edit',
'delete' and reordering buttons that are not seen when the form is acutally
being used.

I would love to have a preview image of what the form will actually look
like when it has been rendered in IE and display it in the form designer.
Much like a the print preview in Word.

I figure that my server would need some component that would acutally render
the page in some invisible IE and then take a screen shot of the web page
and then return the image. The designer could then hyperlink to that image
so the use could see a preview.

Another option would be to have an embedded frame but to adjust its 'zoom'
to be very small. Unfortunately frames do not support such a mythical
'zoom' feature.

Does any one have any idea about how I might solve this problem?

The poor mans option is to have a Preview button in the designer that will
lauch a new browser window and display the form but I am trying to steer
away form this.

Regards
Dave AHi Dave,

If I understand you right, you want to show a preview of the form to your
user, right? How are you rendering the final HTML? Are you using ASP.NET
server controls? Or are you just rendering straight HTML? If you are just
rendering straight HTML, you can update a <div> tag or <asp:Label> control
with your final HTML. You can do this on the server-side by simply
instantiating a HtmlGenericControl for your div tag and updating its
InnerHtml property with your final HTML...i.e. something like this:

<div ID="PreviewPanel" runat="server">
</div
And in your server code:

// optional, depending on if you are using ASP.NET 2.0 or not
public HtmlGenericControl PreviewPanel;

[C#]
string finalHtml = "..."; // set this to your application generates
PreviewPanel.InnerHtml = finalHtml;

Voila, you are now rendering the HTML on the page. Just make sure to do this
upon every refresh, i.e. after every time your client updates something on
the page.

If you want to do something more complicated, i.e. render the ASP.NET server
controls, let me know.

--

Joshua Mitts
joshrm@.msn.com

"Dave A" <dave@.sigmasolutionsdonotspamme.com.au> wrote in message
news:%23YRXaa23FHA.2424@.TK2MSFTNGP10.phx.gbl...
>I am writing an ASP.NET tool that will allow the client to create their own
>online froms. ie the client can add tect boxes, text, drop downs,etc with
>absolutely no technical skill what so ever. The form can then be deployed
>to their intranet.
> The form designer is somewhat WYSIWYG but it contains a heap of 'edit',
> 'delete' and reordering buttons that are not seen when the form is
> acutally being used.
> I would love to have a preview image of what the form will actually look
> like when it has been rendered in IE and display it in the form designer.
> Much like a the print preview in Word.
> I figure that my server would need some component that would acutally
> render the page in some invisible IE and then take a screen shot of the
> web page and then return the image. The designer could then hyperlink to
> that image so the use could see a preview.
> Another option would be to have an embedded frame but to adjust its 'zoom'
> to be very small. Unfortunately frames do not support such a mythical
> 'zoom' feature.
> Does any one have any idea about how I might solve this problem?
> The poor mans option is to have a Preview button in the designer that will
> lauch a new browser window and display the form but I am trying to steer
> away form this.
> Regards
> Dave A
Sorry - I should have been more clear. I want a thumbnail representation of
what the page will actually look like.

Regards
Dave

"Josh Mitts" <joshrm@.msn.com> wrote in message
news:eO%235Ps23FHA.3880@.TK2MSFTNGP12.phx.gbl...
> Hi Dave,
> If I understand you right, you want to show a preview of the form to your
> user, right? How are you rendering the final HTML? Are you using ASP.NET
> server controls? Or are you just rendering straight HTML? If you are just
> rendering straight HTML, you can update a <div> tag or <asp:Label> control
> with your final HTML. You can do this on the server-side by simply
> instantiating a HtmlGenericControl for your div tag and updating its
> InnerHtml property with your final HTML...i.e. something like this:
> <div ID="PreviewPanel" runat="server">
> </div>
> And in your server code:
> // optional, depending on if you are using ASP.NET 2.0 or not
> public HtmlGenericControl PreviewPanel;
> [C#]
> string finalHtml = "..."; // set this to your application generates
> PreviewPanel.InnerHtml = finalHtml;
> Voila, you are now rendering the HTML on the page. Just make sure to do
> this upon every refresh, i.e. after every time your client updates
> something on the page.
> If you want to do something more complicated, i.e. render the ASP.NET
> server controls, let me know.
> --
> Joshua Mitts
> joshrm@.msn.com
>
> "Dave A" <dave@.sigmasolutionsdonotspamme.com.au> wrote in message
> news:%23YRXaa23FHA.2424@.TK2MSFTNGP10.phx.gbl...
>>I am writing an ASP.NET tool that will allow the client to create their
>>own online froms. ie the client can add tect boxes, text, drop downs,etc
>>with absolutely no technical skill what so ever. The form can then be
>>deployed to their intranet.
>>
>> The form designer is somewhat WYSIWYG but it contains a heap of 'edit',
>> 'delete' and reordering buttons that are not seen when the form is
>> acutally being used.
>>
>> I would love to have a preview image of what the form will actually look
>> like when it has been rendered in IE and display it in the form designer.
>> Much like a the print preview in Word.
>>
>> I figure that my server would need some component that would acutally
>> render the page in some invisible IE and then take a screen shot of the
>> web page and then return the image. The designer could then hyperlink to
>> that image so the use could see a preview.
>>
>> Another option would be to have an embedded frame but to adjust its
>> 'zoom' to be very small. Unfortunately frames do not support such a
>> mythical 'zoom' feature.
>>
>> Does any one have any idea about how I might solve this problem?
>>
>> The poor mans option is to have a Preview button in the designer that
>> will lauch a new browser window and display the form but I am trying to
>> steer away form this.
>>
>> Regards
>> Dave A
>>
>>
Here you go

--
Daniel Fisher(lennybacon)
http://www.lennybacon.com

using System;
using System.IO;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;

// Interop
using AxSHDocVw;
using mshtml;
using SHDocVw;

namespace StaticDust
{
/// <summary>
/// Converts HTML documents to PNG format.
/// </summary>
public class Html2Image : System.Windows.Forms.UserControl
{
private AxSHDocVw.AxWebBrowser m_IE;
private System.ComponentModel.Container m_Components = null;

#region Html2Image()
private Html2Image()
{
// setups our embedded ie control
InitializeComponent();
}
#endregion

#region Convert()
/// <summary>
/// Converts a HTML file to a PNG file(s).
/// </summary>
/// <param name="url">A string with the url of the HTML file that should
be converted.</param>
/// <param name="pageLength">A int with the heigth of the PNG file(s).
Use -1 to capture the full HTML file.</param>
/// <param name="outputDir">A <see cref="System.String">string</see> with
the path of the directory, where the PNG file(s) should be saved.</param>
/// <param name="outputFile">A <see cref="System.String">string</see> with
the name of the PNG file(s).</param>
/// <returns>An array with filenames of the created PNG file(s).</returns>
/// <remarks>This method converts a HTML file to PNG file(s).</remarks>
public static String[] Convert(string url, int pageLength, string
outputDir, string outputFile)
{

Html2Image _html2Image = new Html2Image();
_html2Image.CreateControl();
string[] _f = _html2Image.CreateFiles(url, pageLength, outputDir,
outputFile);
_html2Image.Dispose();
return _f;
}
#endregion

#region CreateFiles()
private string[] CreateFiles(string url, int pageLength, string outputDir,
string outputFile)
{
while(!m_IE.Created)
{
Application.DoEvents();
}

object _arg1 = 0;
object _arg2 = "";
object _arg3 = "";
object _arg4 = "";
m_IE.Navigate(url, ref _arg1, ref _arg2, ref _arg3, ref _arg4);

while(!this.m_DocComplete)
{
Application.DoEvents();
}
Application.DoEvents();

while(GetHtmlBody() == null)
{
Application.DoEvents();
}
Application.DoEvents();

m_DocComplete = false;
m_IE.Navigate(url, ref _arg1, ref _arg2, ref _arg3, ref _arg4);
while(!this.m_DocComplete)
{
Application.DoEvents();
}
Application.DoEvents();

while(GetHtmlBody() == null)
{
Application.DoEvents();
}
Application.DoEvents();

for(int i=0; i<2000000; i++)
{
Application.DoEvents();
}

m_DocComplete = false;
m_IE.Navigate(url, ref _arg1, ref _arg2, ref _arg3, ref _arg4);
while(!this.m_DocComplete)
{
Application.DoEvents();
}
Application.DoEvents();

for(int i=0; i<2000000; i++)
{
Application.DoEvents();
}

while(GetHtmlBody() == null)
{
Application.DoEvents();
}
Application.DoEvents();

Bitmap _htmlimage = CaptureImage();

if (_htmlimage!=null)
{
if(pageLength==-1)
{
pageLength = _htmlimage.Height;
}

Bitmap _pageBitmap = new Bitmap(_htmlimage.Width, pageLength);
Graphics _g = Graphics.FromImage(_pageBitmap);

int _p = (int)Math.Floor(_htmlimage.Height/pageLength);
if(_p*pageLength<_htmlimage.Height)
{
_p++;
}

string[] _files = new string[_p];
for (int i=0;i<_files.GetLength(0);i++)
{
_g.Clear(Color.White);
_g.DrawImage(_htmlimage, new Rectangle(0, 0, _pageBitmap.Width,
pageLength), new Rectangle(0, (i*pageLength), _pageBitmap.Width,
pageLength), GraphicsUnit.Pixel);
_files[i] = Path.Combine(outputDir, outputFile+i+".png");
_pageBitmap.Save(_files[i], ImageFormat.Png);
}

_htmlimage.Dispose();
_g.Dispose();
_pageBitmap.Dispose();
return _files;
}
return null;
}
#endregion

#region OnDocumentComplete()
private bool m_DocComplete = false;
private void OnDocumentComplete(object sender,
AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent e)
{
m_DocComplete = true;
}
#endregion

#region CaptureImage()
private Bitmap CaptureImage()
{
try
{
IHTMLElement2 _htmlBody2 = GetHtmlBody();
Application.DoEvents();
int _w = _htmlBody2.scrollWidth;
int _h = _htmlBody2.scrollHeight;

// Make our embedded ie control that size
if((m_IE.Height != _h + 30) || (m_IE.Width != _w + 30))
{
m_IE.Height = _h + 30;
m_IE.Width = _w + 30;
}

// Setup bitmap memory and wrap a DC around it
Bitmap _bitmap = new Bitmap(_w, _h, PixelFormat.Format24bppRgb);
Graphics _graphics = Graphics.FromImage(_bitmap);
IntPtr _memdc = _graphics.GetHdc();
IntPtr _hbitmap = _bitmap.GetHbitmap();
SelectObject(_memdc, _hbitmap);

// Tell ie to print into our dc/bitmap

// Use PrintWindow windows api
//
const uint PW_CLIENTONLY = 0x00000001;
//
bool _rv = PrintWindow(m_IE.Handle, _memdc, PW_CLIENTONLY);

// Send it a print msg + flags
const uint WM_PRINT = 0x0317;
// const uint WM_PRINTCLIENT = 0x0318;
// const uint PRF_CHECKVISIBLE = 0x00000001;
const uint PRF_NONCLIENT = 0x00000002;
const uint PRF_CLIENT = 0x00000004;
const uint PRF_ERASEBKGND = 0x00000008;
const uint PRF_CHILDREN = 0x00000010;
const uint PRF_OWNED = 0x00000020;
int _err = SendMessage(m_IE.Handle, WM_PRINT, (uint)_memdc, (uint)
(PRF_CLIENT | PRF_NONCLIENT | PRF_OWNED | PRF_CHILDREN | PRF_ERASEBKGND));

// Save image
Bitmap _bitmap2 = Bitmap.FromHbitmap(_hbitmap);

// Cleanup
DeleteObject(_hbitmap);
_graphics.ReleaseHdc(_memdc);
_graphics.Dispose();
_bitmap.Dispose();

return _bitmap2;

}
catch(Exception ex)
{
System.Console.WriteLine("Exception: " + ex.Message + "\n");
System.Console.WriteLine(" source: " + ex.Source + "\n");
System.Console.WriteLine(" stacktrace:" + ex.StackTrace + "\n");
throw;
}

}
#endregion

#region Dispose()
/// <summary>
/// Releases the unmanaged resources used by the Control and its child
controls and optionally releases the managed resources.
/// </summary>
/// <param name="disposing"><b>true</b> to release both managed and
unmanaged resources; <b>false</b> to release only unmanaged resources.
</param>
/// <remarks>
/// This method is called by the public Dispose() method and the Finalize
method. <b>Dispose()</b>
/// invokes the protected <b>Dispose(Boolean)</b> method with
/// the <i>disposing</i> parameter set to <b>true</b>. <b>Finalize</b>
invokes <b>Dispose</b> with <i>disposing</i> set to <b>false</b>.
/// <br/>When the <i>disposing</i> parameter is <b>true</b>, this method
releases all resources held by any managed
/// objects that this Control and its child controls reference. This
method invokes the <b>Dispose()</b>
/// method of each referenced object.
/// <br/><b>Notes to Inheritors:</b> <b>Dispose</b> can be called
multiple times by other objects. When overriding
/// <b>Dispose(Boolean)</b>, be careful not to reference objects that have
been previously disposed of in
/// an earlier call to <b>Dispose</b>.
/// </remarks>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(m_Components != null)
{
m_Components.Dispose();
}
}
base.Dispose( disposing );
}
#endregion

#region InitializeComponent()
private void InitializeComponent()
{
System.Resources.ResourceManager _resources = new
System.Resources.ResourceManager(typeof(Html2Image ));
this.m_IE = new AxSHDocVw.AxWebBrowser();
((System.ComponentModel.ISupportInitialize)(this.m _IE)).BeginInit();
this.SuspendLayout();
//
// m_IE
//
this.m_IE.Enabled = true;
this.m_IE.Location = new System.Drawing.Point(0, 0);
//this.m_IE.OcxState =
((System.Windows.Forms.AxHost.State)(resources.Get Object("m_IE.OcxState")));
this.m_IE.Size = new System.Drawing.Size(804, 580);
this.m_IE.TabIndex = 7;
this.m_IE.DocumentComplete += new
AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent Handler(this.OnDocumentComplete);

//
// Html2Image
//
this.Controls.AddRange(new System.Windows.Forms.Control[] { this.m_IE});
this.Size = new System.Drawing.Size(292, 266);
((System.ComponentModel.ISupportInitialize)(this.m _IE)).EndInit();
this.ResumeLayout(false);
}
#endregion

//IE InterOp

#region IHTMLElement2 GetHtmlBody()
private IHTMLElement2 GetHtmlBody()
{
IWebBrowser2 _wb2 = (IWebBrowser2) m_IE.GetOcx();
Application.DoEvents();
IHTMLDocument2 _htmlDocument2 = (IHTMLDocument2) _wb2.Document;
Application.DoEvents();
return (IHTMLElement2)_htmlDocument2.body;
}
#endregion

//Win32 InterOp

#region extern IntPtr SelectObject()
[DllImport("Gdi32.dll")]
private static extern IntPtr SelectObject(
IntPtr hdc, // handle to DC
IntPtr hgdiobj // handle to object
);
#endregion

#region extern bool DeleteObject()
[DllImport("Gdi32.dll")]
private static extern bool DeleteObject(
IntPtr hObject // handle to graphic object
);
#endregion

#region extern IntPtr CreateCompatibleDC()
[DllImport("Gdi32.dll")]
private static extern IntPtr CreateCompatibleDC(
IntPtr hdc // handle to DC
);
#endregion

#region extern bool DeleteDC()
[DllImport("Gdi32.dll")]
private static extern bool DeleteDC(
IntPtr hdc // handle to DC
);
#endregion

#region extern bool PrintWindow()
[DllImport("User32.dll")]
private static extern bool PrintWindow(
IntPtr hwnd, // Window to copy
IntPtr hdcBlt, // HDC to print into
uint nFlags // Optional flags // must contain PW_CLIENTONLY
);
#endregion

#region extern int SendMessage()
[DllImport("User32.dll")]
private static extern int SendMessage(
IntPtr hWnd, // handle to destination window
uint Msg, // message
uint wParam, // firstmessage parameter
uint lParam // second message parameter
);
#endregion

}
}

"Dave A" <dave@.sigmasolutionsdonotspamme.com.au> wrote in message
news:eIhiZOF4FHA.3628@.TK2MSFTNGP12.phx.gbl...
> Sorry - I should have been more clear. I want a thumbnail representation
> of what the page will actually look like.
> Regards
> Dave
> "Josh Mitts" <joshrm@.msn.com> wrote in message
> news:eO%235Ps23FHA.3880@.TK2MSFTNGP12.phx.gbl...
>> Hi Dave,
>>
>> If I understand you right, you want to show a preview of the form to your
>> user, right? How are you rendering the final HTML? Are you using ASP.NET
>> server controls? Or are you just rendering straight HTML? If you are just
>> rendering straight HTML, you can update a <div> tag or <asp:Label>
>> control with your final HTML. You can do this on the server-side by
>> simply instantiating a HtmlGenericControl for your div tag and updating
>> its InnerHtml property with your final HTML...i.e. something like this:
>>
>> <div ID="PreviewPanel" runat="server">
>> </div>
>>
>> And in your server code:
>>
>> // optional, depending on if you are using ASP.NET 2.0 or not
>> public HtmlGenericControl PreviewPanel;
>>
>> [C#]
>> string finalHtml = "..."; // set this to your application generates
>> PreviewPanel.InnerHtml = finalHtml;
>>
>> Voila, you are now rendering the HTML on the page. Just make sure to do
>> this upon every refresh, i.e. after every time your client updates
>> something on the page.
>>
>> If you want to do something more complicated, i.e. render the ASP.NET
>> server controls, let me know.
>>
>> --
>>
>> Joshua Mitts
>> joshrm@.msn.com
>>
>>
>> "Dave A" <dave@.sigmasolutionsdonotspamme.com.au> wrote in message
>> news:%23YRXaa23FHA.2424@.TK2MSFTNGP10.phx.gbl...
>>>I am writing an ASP.NET tool that will allow the client to create their
>>>own online froms. ie the client can add tect boxes, text, drop downs,etc
>>>with absolutely no technical skill what so ever. The form can then be
>>>deployed to their intranet.
>>>
>>> The form designer is somewhat WYSIWYG but it contains a heap of 'edit',
>>> 'delete' and reordering buttons that are not seen when the form is
>>> acutally being used.
>>>
>>> I would love to have a preview image of what the form will actually look
>>> like when it has been rendered in IE and display it in the form
>>> designer. Much like a the print preview in Word.
>>>
>>> I figure that my server would need some component that would acutally
>>> render the page in some invisible IE and then take a screen shot of the
>>> web page and then return the image. The designer could then hyperlink
>>> to that image so the use could see a preview.
>>>
>>> Another option would be to have an embedded frame but to adjust its
>>> 'zoom' to be very small. Unfortunately frames do not support such a
>>> mythical 'zoom' feature.
>>>
>>> Does any one have any idea about how I might solve this problem?
>>>
>>> The poor mans option is to have a Preview button in the designer that
>>> will lauch a new browser window and display the form but I am trying to
>>> steer away form this.
>>>
>>> Regards
>>> Dave A
>>>
>>>
>>
>>
Holy crap! Well done man! I would never have worked this out and thought
that it was impossible. I am pleased that I asked.

Regards
Dave

"Daniel Fisher(lennybacon)" <info@.lennybacon.com> wrote in message
news:OHj8PjF4FHA.3628@.TK2MSFTNGP12.phx.gbl...
> Here you go
> --
> Daniel Fisher(lennybacon)
> http://www.lennybacon.com
> using System;
> using System.IO;
> using System.Collections;
> using System.ComponentModel;
> using System.Drawing;
> using System.Data;
> using System.Windows.Forms;
> using System.Drawing.Imaging;
> using System.Runtime.InteropServices;
> // Interop
> using AxSHDocVw;
> using mshtml;
> using SHDocVw;
> namespace StaticDust
> {
> /// <summary>
> /// Converts HTML documents to PNG format.
> /// </summary>
> public class Html2Image : System.Windows.Forms.UserControl
> {
> private AxSHDocVw.AxWebBrowser m_IE;
> private System.ComponentModel.Container m_Components = null;
> #region Html2Image()
> private Html2Image()
> {
> // setups our embedded ie control
> InitializeComponent();
> }
> #endregion
> #region Convert()
> /// <summary>
> /// Converts a HTML file to a PNG file(s).
> /// </summary>
> /// <param name="url">A string with the url of the HTML file that should
> be converted.</param>
> /// <param name="pageLength">A int with the heigth of the PNG file(s).
> Use -1 to capture the full HTML file.</param>
> /// <param name="outputDir">A <see cref="System.String">string</see> with
> the path of the directory, where the PNG file(s) should be saved.</param>
> /// <param name="outputFile">A <see cref="System.String">string</see>
> with the name of the PNG file(s).</param>
> /// <returns>An array with filenames of the created PNG
> file(s).</returns>
> /// <remarks>This method converts a HTML file to PNG file(s).</remarks>
> public static String[] Convert(string url, int pageLength, string
> outputDir, string outputFile)
> {
> Html2Image _html2Image = new Html2Image();
> _html2Image.CreateControl();
> string[] _f = _html2Image.CreateFiles(url, pageLength, outputDir,
> outputFile);
> _html2Image.Dispose();
> return _f;
> }
> #endregion
> #region CreateFiles()
> private string[] CreateFiles(string url, int pageLength, string
> outputDir, string outputFile)
> {
> while(!m_IE.Created)
> {
> Application.DoEvents();
> }
> object _arg1 = 0;
> object _arg2 = "";
> object _arg3 = "";
> object _arg4 = "";
> m_IE.Navigate(url, ref _arg1, ref _arg2, ref _arg3, ref _arg4);
> while(!this.m_DocComplete)
> {
> Application.DoEvents();
> }
> Application.DoEvents();
> while(GetHtmlBody() == null)
> {
> Application.DoEvents();
> }
> Application.DoEvents();
> m_DocComplete = false;
> m_IE.Navigate(url, ref _arg1, ref _arg2, ref _arg3, ref _arg4);
> while(!this.m_DocComplete)
> {
> Application.DoEvents();
> }
> Application.DoEvents();
> while(GetHtmlBody() == null)
> {
> Application.DoEvents();
> }
> Application.DoEvents();
> for(int i=0; i<2000000; i++)
> {
> Application.DoEvents();
> }
> m_DocComplete = false;
> m_IE.Navigate(url, ref _arg1, ref _arg2, ref _arg3, ref _arg4);
> while(!this.m_DocComplete)
> {
> Application.DoEvents();
> }
> Application.DoEvents();
> for(int i=0; i<2000000; i++)
> {
> Application.DoEvents();
> }
> while(GetHtmlBody() == null)
> {
> Application.DoEvents();
> }
> Application.DoEvents();
>
> Bitmap _htmlimage = CaptureImage();
> if (_htmlimage!=null)
> {
> if(pageLength==-1)
> {
> pageLength = _htmlimage.Height;
> }
> Bitmap _pageBitmap = new Bitmap(_htmlimage.Width, pageLength);
> Graphics _g = Graphics.FromImage(_pageBitmap);
> int _p = (int)Math.Floor(_htmlimage.Height/pageLength);
> if(_p*pageLength<_htmlimage.Height)
> {
> _p++;
> }
> string[] _files = new string[_p];
> for (int i=0;i<_files.GetLength(0);i++)
> {
> _g.Clear(Color.White);
> _g.DrawImage(_htmlimage, new Rectangle(0, 0, _pageBitmap.Width,
> pageLength), new Rectangle(0, (i*pageLength), _pageBitmap.Width,
> pageLength), GraphicsUnit.Pixel);
> _files[i] = Path.Combine(outputDir, outputFile+i+".png");
> _pageBitmap.Save(_files[i], ImageFormat.Png);
> }
> _htmlimage.Dispose();
> _g.Dispose();
> _pageBitmap.Dispose();
> return _files;
> }
> return null;
> }
> #endregion
> #region OnDocumentComplete()
> private bool m_DocComplete = false;
> private void OnDocumentComplete(object sender,
> AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent e)
> {
> m_DocComplete = true;
> }
> #endregion
>
> #region CaptureImage()
> private Bitmap CaptureImage()
> {
> try
> {
> IHTMLElement2 _htmlBody2 = GetHtmlBody();
> Application.DoEvents();
> int _w = _htmlBody2.scrollWidth;
> int _h = _htmlBody2.scrollHeight;
> // Make our embedded ie control that size
> if((m_IE.Height != _h + 30) || (m_IE.Width != _w + 30))
> {
> m_IE.Height = _h + 30;
> m_IE.Width = _w + 30;
> }
> // Setup bitmap memory and wrap a DC around it
> Bitmap _bitmap = new Bitmap(_w, _h, PixelFormat.Format24bppRgb);
> Graphics _graphics = Graphics.FromImage(_bitmap);
> IntPtr _memdc = _graphics.GetHdc();
> IntPtr _hbitmap = _bitmap.GetHbitmap();
> SelectObject(_memdc, _hbitmap);
> // Tell ie to print into our dc/bitmap
> // Use PrintWindow windows api
> //
> const uint PW_CLIENTONLY = 0x00000001;
> //
> bool _rv = PrintWindow(m_IE.Handle, _memdc, PW_CLIENTONLY);
> // Send it a print msg + flags
> const uint WM_PRINT = 0x0317;
> // const uint WM_PRINTCLIENT = 0x0318;
> // const uint PRF_CHECKVISIBLE = 0x00000001;
> const uint PRF_NONCLIENT = 0x00000002;
> const uint PRF_CLIENT = 0x00000004;
> const uint PRF_ERASEBKGND = 0x00000008;
> const uint PRF_CHILDREN = 0x00000010;
> const uint PRF_OWNED = 0x00000020;
> int _err = SendMessage(m_IE.Handle, WM_PRINT, (uint)_memdc, (uint)
> (PRF_CLIENT | PRF_NONCLIENT | PRF_OWNED | PRF_CHILDREN | PRF_ERASEBKGND));
> // Save image
> Bitmap _bitmap2 = Bitmap.FromHbitmap(_hbitmap);
> // Cleanup
> DeleteObject(_hbitmap);
> _graphics.ReleaseHdc(_memdc);
> _graphics.Dispose();
> _bitmap.Dispose();
> return _bitmap2;
> }
> catch(Exception ex)
> {
> System.Console.WriteLine("Exception: " + ex.Message + "\n");
> System.Console.WriteLine(" source: " + ex.Source + "\n");
> System.Console.WriteLine(" stacktrace:" + ex.StackTrace + "\n");
> throw;
> }
> }
> #endregion
>
> #region Dispose()
> /// <summary>
> /// Releases the unmanaged resources used by the Control and its child
> controls and optionally releases the managed resources.
> /// </summary>
> /// <param name="disposing"><b>true</b> to release both managed and
> unmanaged resources; <b>false</b> to release only unmanaged resources.
> </param>
> /// <remarks>
> /// This method is called by the public Dispose() method and the Finalize
> method. <b>Dispose()</b>
> /// invokes the protected <b>Dispose(Boolean)</b> method with
> /// the <i>disposing</i> parameter set to <b>true</b>. <b>Finalize</b>
> invokes <b>Dispose</b> with <i>disposing</i> set to <b>false</b>.
> /// <br/>When the <i>disposing</i> parameter is <b>true</b>, this method
> releases all resources held by any managed
> /// objects that this Control and its child controls reference. This
> method invokes the <b>Dispose()</b>
> /// method of each referenced object.
> /// <br/><b>Notes to Inheritors:</b> <b>Dispose</b> can be called
> multiple times by other objects. When overriding
> /// <b>Dispose(Boolean)</b>, be careful not to reference objects that
> have been previously disposed of in
> /// an earlier call to <b>Dispose</b>.
> /// </remarks>
> protected override void Dispose( bool disposing )
> {
> if( disposing )
> {
> if(m_Components != null)
> {
> m_Components.Dispose();
> }
> }
> base.Dispose( disposing );
> }
> #endregion
> #region InitializeComponent()
> private void InitializeComponent()
> {
> System.Resources.ResourceManager _resources = new
> System.Resources.ResourceManager(typeof(Html2Image ));
> this.m_IE = new AxSHDocVw.AxWebBrowser();
> ((System.ComponentModel.ISupportInitialize)(this.m _IE)).BeginInit();
> this.SuspendLayout();
> //
> // m_IE
> //
> this.m_IE.Enabled = true;
> this.m_IE.Location = new System.Drawing.Point(0, 0);
> //this.m_IE.OcxState =
> ((System.Windows.Forms.AxHost.State)(resources.Get Object("m_IE.OcxState")));
> this.m_IE.Size = new System.Drawing.Size(804, 580);
> this.m_IE.TabIndex = 7;
> this.m_IE.DocumentComplete += new
> AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent Handler(this.OnDocumentComplete);
> //
> // Html2Image
> //
> this.Controls.AddRange(new System.Windows.Forms.Control[] { this.m_IE});
> this.Size = new System.Drawing.Size(292, 266);
> ((System.ComponentModel.ISupportInitialize)(this.m _IE)).EndInit();
> this.ResumeLayout(false);
> }
> #endregion
>
> //IE InterOp
> #region IHTMLElement2 GetHtmlBody()
> private IHTMLElement2 GetHtmlBody()
> {
> IWebBrowser2 _wb2 = (IWebBrowser2) m_IE.GetOcx();
> Application.DoEvents();
> IHTMLDocument2 _htmlDocument2 = (IHTMLDocument2) _wb2.Document;
> Application.DoEvents();
> return (IHTMLElement2)_htmlDocument2.body;
> }
> #endregion
>
> //Win32 InterOp
> #region extern IntPtr SelectObject()
> [DllImport("Gdi32.dll")]
> private static extern IntPtr SelectObject(
> IntPtr hdc, // handle to DC
> IntPtr hgdiobj // handle to object
> );
> #endregion
> #region extern bool DeleteObject()
> [DllImport("Gdi32.dll")]
> private static extern bool DeleteObject(
> IntPtr hObject // handle to graphic object
> );
> #endregion
> #region extern IntPtr CreateCompatibleDC()
> [DllImport("Gdi32.dll")]
> private static extern IntPtr CreateCompatibleDC(
> IntPtr hdc // handle to DC
> );
> #endregion
> #region extern bool DeleteDC()
> [DllImport("Gdi32.dll")]
> private static extern bool DeleteDC(
> IntPtr hdc // handle to DC
> );
> #endregion
> #region extern bool PrintWindow()
> [DllImport("User32.dll")]
> private static extern bool PrintWindow(
> IntPtr hwnd, // Window to copy
> IntPtr hdcBlt, // HDC to print into
> uint nFlags // Optional flags // must contain
> PW_CLIENTONLY
> );
> #endregion
> #region extern int SendMessage()
> [DllImport("User32.dll")]
> private static extern int SendMessage(
> IntPtr hWnd, // handle to destination window
> uint Msg, // message
> uint wParam, // firstmessage parameter
> uint lParam // second message parameter
> );
> #endregion
> }
> }
>
> "Dave A" <dave@.sigmasolutionsdonotspamme.com.au> wrote in message
> news:eIhiZOF4FHA.3628@.TK2MSFTNGP12.phx.gbl...
>> Sorry - I should have been more clear. I want a thumbnail representation
>> of what the page will actually look like.
>>
>> Regards
>> Dave
>>
>> "Josh Mitts" <joshrm@.msn.com> wrote in message
>> news:eO%235Ps23FHA.3880@.TK2MSFTNGP12.phx.gbl...
>>> Hi Dave,
>>>
>>> If I understand you right, you want to show a preview of the form to
>>> your user, right? How are you rendering the final HTML? Are you using
>>> ASP.NET server controls? Or are you just rendering straight HTML? If you
>>> are just rendering straight HTML, you can update a <div> tag or
>>> <asp:Label> control with your final HTML. You can do this on the
>>> server-side by simply instantiating a HtmlGenericControl for your div
>>> tag and updating its InnerHtml property with your final HTML...i.e.
>>> something like this:
>>>
>>> <div ID="PreviewPanel" runat="server">
>>> </div>
>>>
>>> And in your server code:
>>>
>>> // optional, depending on if you are using ASP.NET 2.0 or not
>>> public HtmlGenericControl PreviewPanel;
>>>
>>> [C#]
>>> string finalHtml = "..."; // set this to your application generates
>>> PreviewPanel.InnerHtml = finalHtml;
>>>
>>> Voila, you are now rendering the HTML on the page. Just make sure to do
>>> this upon every refresh, i.e. after every time your client updates
>>> something on the page.
>>>
>>> If you want to do something more complicated, i.e. render the ASP.NET
>>> server controls, let me know.
>>>
>>> --
>>>
>>> Joshua Mitts
>>> joshrm@.msn.com
>>>
>>>
>>> "Dave A" <dave@.sigmasolutionsdonotspamme.com.au> wrote in message
>>> news:%23YRXaa23FHA.2424@.TK2MSFTNGP10.phx.gbl...
>>>>I am writing an ASP.NET tool that will allow the client to create their
>>>>own online froms. ie the client can add tect boxes, text, drop
>>>>downs,etc with absolutely no technical skill what so ever. The form can
>>>>then be deployed to their intranet.
>>>>
>>>> The form designer is somewhat WYSIWYG but it contains a heap of 'edit',
>>>> 'delete' and reordering buttons that are not seen when the form is
>>>> acutally being used.
>>>>
>>>> I would love to have a preview image of what the form will actually
>>>> look like when it has been rendered in IE and display it in the form
>>>> designer. Much like a the print preview in Word.
>>>>
>>>> I figure that my server would need some component that would acutally
>>>> render the page in some invisible IE and then take a screen shot of the
>>>> web page and then return the image. The designer could then hyperlink
>>>> to that image so the use could see a preview.
>>>>
>>>> Another option would be to have an embedded frame but to adjust its
>>>> 'zoom' to be very small. Unfortunately frames do not support such a
>>>> mythical 'zoom' feature.
>>>>
>>>> Does any one have any idea about how I might solve this problem?
>>>>
>>>> The poor mans option is to have a Preview button in the designer that
>>>> will lauch a new browser window and display the form but I am trying to
>>>> steer away form this.
>>>>
>>>> Regards
>>>> Dave A
>>>>
>>>>
>>>
>>>
>>
>>
Will this work with .Net 2.0 ?
Do any special references need to be added to the project?

--Alex

Server SIde Validation Issue

Hello,

I have several client side validation controls that cause an error message to be displayed in the validation summary control.

For one control, custom control, I am required to do SERVER SIDE VALIDATION.

I have the follwing code:

protected void validatePass_ServerValidate(object source, ServerValidateEventArgs args)
{
if (txtPass.Text != "Mohit")
{ validatePass.IsValid = false;
validatePass.ErrorMessage = "Wrong Password!";
}
else validatePass.IsValid = true;

}

When I enter the wrong password though I do not see the custom control generate any error message and I do not see any error message in the summary control either.

Any assisatance would be appreciated.When the wrong password is entered and the user submits the page, in the page load event or the button click event, do a check for if(Page.IsValid)
I appreciate your response.

I am afraid that I am a newbie and will need a little bit of help here.

Can you provide some pseudo code as to what I should do and can you please make any modifications to the code I provided if necessary.

Thanks!
Let's deal with this in a single thread, yeah?

http://www.vbforums.com/showthread.php?t=491694

(Since they're related questions)

Monday, March 26, 2012

Server Time || Client Time

Hi everyone,

How to get Server time and Client time with ASP.NET script?
Could any1 show me the script>?

Thanks.Hi,


HTML:
<asp:label id="lblServerTime" runat="server">Label</asp:label>
<span id="ClientTime"></span
Codebehind:
private void Page_Load(object sender, System.EventArgs e)
{
lblServerTime.Text = "Setver Time: " + DateTime.Now.ToString();
RegisterStartupScript("ClientTime", "<script>var d = new Date();getElementById('ClientTime').value=(d.getMonth()+1)+'/'+d.getDate()+'/'+d.getYear();</script>");
}

Thanks for the code but I am sorry to say I do know only VB. So please , code in VB.
I guess it's going to be as below


Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)

lblServerTime.Text = "Setver Time: " & DateTime.Now.ToString()

RegisterStartupScript("ClientTime", "<script>var d = new Date();getElementById('ClientTime').value=(d.getMonth()+1)+'/'+d.getDate()+'/'+d.getYear();</script>")

End Sub


Thanks for your help.

I accepted your answer

Saturday, March 24, 2012

server updateing data already on the client

Hi

I would like that when data is updated in a database on
the sever taht all instance of that data already being
viewed on aspx pages by clients be updated. Is this
acheiveble with an activeX control on the page that
listens for information from the server? I dont want to
have to use page refreshes firing in a loop.

Thanks in advance

JakeYou can write a Windows Form application and host it in a browser, just like
ActiveX. You'll need to use remoting for that though.
The catch is that every user must have IE and .NET framework installed.
Other browsers don't support .NET "applets"

"Jake" <anonymous@.discussions.microsoft.com> wrote in message
news:2418501c45f00$7f8a8640$a501280a@.phx.gbl...
> Hi
> I would like that when data is updated in a database on
> the sever taht all instance of that data already being
> viewed on aspx pages by clients be updated. Is this
> acheiveble with an activeX control on the page that
> listens for information from the server? I dont want to
> have to use page refreshes firing in a loop.
> Thanks in advance
> Jake
Thanks that sounds exactly like what I am after.

Would you know of where I can find information about
imbeding/running windows application in a web page/
browser and remoting?

Thanks again

Jake

>--Original Message--
>You can write a Windows Form application and host it in
a browser, just like
>ActiveX. You'll need to use remoting for that though.
>The catch is that every user must have IE and .NET
framework installed.
>Other browsers don't support .NET "applets"
>"Jake" <anonymous@.discussions.microsoft.com> wrote in
message
>news:2418501c45f00$7f8a8640$a501280a@.phx.gbl...
>> Hi
>>
>> I would like that when data is updated in a database on
>> the sever taht all instance of that data already being
>> viewed on aspx pages by clients be updated. Is this
>> acheiveble with an activeX control on the page that
>> listens for information from the server? I dont want
to
>> have to use page refreshes firing in a loop.
>>
>> Thanks in advance
>>
>> Jake
>
>.

server updateing data already on the client

Hi
I would like that when data is updated in a database on
the sever taht all instance of that data already being
viewed on aspx pages by clients be updated. Is this
acheiveble with an activeX control on the page that
listens for information from the server? I dont want to
have to use page refreshes firing in a loop.
Thanks in advance
JakeYou can write a Windows Form application and host it in a browser, just like
ActiveX. You'll need to use remoting for that though.
The catch is that every user must have IE and .NET framework installed.
Other browsers don't support .NET "applets"
"Jake" <anonymous@.discussions.microsoft.com> wrote in message
news:2418501c45f00$7f8a8640$a501280a@.phx
.gbl...
> Hi
> I would like that when data is updated in a database on
> the sever taht all instance of that data already being
> viewed on aspx pages by clients be updated. Is this
> acheiveble with an activeX control on the page that
> listens for information from the server? I dont want to
> have to use page refreshes firing in a loop.
> Thanks in advance
> Jake
Thanks that sounds exactly like what I am after.
Would you know of where I can find information about
imbeding/running windows application in a web page/
browser and remoting?
Thanks again
Jake

>--Original Message--
>You can write a Windows Form application and host it in
a browser, just like
>ActiveX. You'll need to use remoting for that though.
>The catch is that every user must have IE and .NET
framework installed.
>Other browsers don't support .NET "applets"
>"Jake" <anonymous@.discussions.microsoft.com> wrote in
message
> news:2418501c45f00$7f8a8640$a501280a@.phx
.gbl...
to
>
>.
>

Server Variable in Client Script

Hi All,

I am trying to pass a variable from my VB asp.net script (from for example
Sub Page_Load in mypage.aspx.vb) to my Client side script.

I have found and looked at a very good example "Client and Server Scripting
in Web Pages" but it only shows server side scripting that is written in
HTML in mypage.aspx and not script from mypage.aspx.vb. How can I pass a
variable value from mypage.aspx.vp to my client side script?

Sample from "Client and Server Scripting in Web Pages"

<%@dotnet.itags.org. LANGUAGE="VBSCRIPT" %
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual InterDev 1.0">
<META HTTP-EQUIV="Content-Type" content="text/html; charset=iso-8859-1">
<TITLE>Document Title</TITLE>
</HEAD>
<BODY
<% Dim strMyServerVar
strMyServerVar = 42 %>
.......

The following line of HTML was generated on the client to print the value of
a client variable into the page after the page was sent to the browser. The
value of the client variable has been set equal to the value of the server
variable printed above.
<BR>
<BR>
<SCRIPT LANGUAGE = "JavaScript">
<!--
var x ;
x = <%= strMyServerVar %> ;
if (x == <%= strMyServerVar%>) {
document.write ("<STRONG>The value of the client variable is " + x +
".</STRONG>")
}
//
-->
</SCRIPTFew ways... build your clientside script dynamically from within your server
side script, passing in the values.
Also, could always put the values in a hidden text box and have the
clientside pull from that.

--
Curt Christianson
Owner/Lead Developer, DF-Software
www.Darkfalz.com

"Bob T" <twick10@.hotmail.com> wrote in message
news:e9G7ajs1DHA.2604@.TK2MSFTNGP09.phx.gbl...
> Hi All,
> I am trying to pass a variable from my VB asp.net script (from for example
> Sub Page_Load in mypage.aspx.vb) to my Client side script.
> I have found and looked at a very good example "Client and Server
Scripting
> in Web Pages" but it only shows server side scripting that is written in
> HTML in mypage.aspx and not script from mypage.aspx.vb. How can I pass a
> variable value from mypage.aspx.vp to my client side script?
>
> Sample from "Client and Server Scripting in Web Pages"
> <%@. LANGUAGE="VBSCRIPT" %>
> <HTML>
> <HEAD>
> <META NAME="GENERATOR" Content="Microsoft Visual InterDev 1.0">
> <META HTTP-EQUIV="Content-Type" content="text/html; charset=iso-8859-1">
> <TITLE>Document Title</TITLE>
> </HEAD>
> <BODY>
> <% Dim strMyServerVar
> strMyServerVar = 42 %>
> ......
> The following line of HTML was generated on the client to print the value
of
> a client variable into the page after the page was sent to the browser.
The
> value of the client variable has been set equal to the value of the server
> variable printed above.
> <BR>
> <BR>
> <SCRIPT LANGUAGE = "JavaScript">
> <!--
> var x ;
> x = <%= strMyServerVar %> ;
> if (x == <%= strMyServerVar%>) {
> document.write ("<STRONG>The value of the client variable is " + x +
> ".</STRONG>")
> }
> //
> -->
> </SCRIPT>
Bob,

Why would you do this?

The whole point of using a code behind page is so that the programming logic
can be separated from the display. Placing the programming logic in both
places defeats one of the best things about .NET.

Just Dim your variable in the code behind and you're done.

Move this line to the code behind page like this:

Public Class WebForm1
Inherits System.Web.UI.Page
Public strMyServerVar As String = "42"
'--Rest of page code below

And remove the variable declaration from the .aspx page altogether:
Delete This: <% Dim strMyServerVar strMyServerVar = 42 %
Your code will still work the same way. The .aspx page will have access to
the variable because it's declared as Public (you could also declare it as
Protected or Protected Friend)

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche

"Bob T" <twick10@.hotmail.com> wrote in message
news:e9G7ajs1DHA.2604@.TK2MSFTNGP09.phx.gbl...
> Hi All,
> I am trying to pass a variable from my VB asp.net script (from for example
> Sub Page_Load in mypage.aspx.vb) to my Client side script.
> I have found and looked at a very good example "Client and Server
Scripting
> in Web Pages" but it only shows server side scripting that is written in
> HTML in mypage.aspx and not script from mypage.aspx.vb. How can I pass a
> variable value from mypage.aspx.vp to my client side script?
>
> Sample from "Client and Server Scripting in Web Pages"
> <%@. LANGUAGE="VBSCRIPT" %>
> <HTML>
> <HEAD>
> <META NAME="GENERATOR" Content="Microsoft Visual InterDev 1.0">
> <META HTTP-EQUIV="Content-Type" content="text/html; charset=iso-8859-1">
> <TITLE>Document Title</TITLE>
> </HEAD>
> <BODY>
> <% Dim strMyServerVar
> strMyServerVar = 42 %>
> ......
> The following line of HTML was generated on the client to print the value
of
> a client variable into the page after the page was sent to the browser.
The
> value of the client variable has been set equal to the value of the server
> variable printed above.
> <BR>
> <BR>
> <SCRIPT LANGUAGE = "JavaScript">
> <!--
> var x ;
> x = <%= strMyServerVar %> ;
> if (x == <%= strMyServerVar%>) {
> document.write ("<STRONG>The value of the client variable is " + x +
> ".</STRONG>")
> }
> //
> -->
> </SCRIPT>
Bob,

Just a quick note. My previous message shows how to do what you want, but I
shouldn't have included the "Why would you do this?" at the top of the
message.

I misunderstood part of your question.

Still, the code I provided does what you need.

Happy programming!

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche

"Bob T" <twick10@.hotmail.com> wrote in message
news:e9G7ajs1DHA.2604@.TK2MSFTNGP09.phx.gbl...
> Hi All,
> I am trying to pass a variable from my VB asp.net script (from for example
> Sub Page_Load in mypage.aspx.vb) to my Client side script.
> I have found and looked at a very good example "Client and Server
Scripting
> in Web Pages" but it only shows server side scripting that is written in
> HTML in mypage.aspx and not script from mypage.aspx.vb. How can I pass a
> variable value from mypage.aspx.vp to my client side script?
>
> Sample from "Client and Server Scripting in Web Pages"
> <%@. LANGUAGE="VBSCRIPT" %>
> <HTML>
> <HEAD>
> <META NAME="GENERATOR" Content="Microsoft Visual InterDev 1.0">
> <META HTTP-EQUIV="Content-Type" content="text/html; charset=iso-8859-1">
> <TITLE>Document Title</TITLE>
> </HEAD>
> <BODY>
> <% Dim strMyServerVar
> strMyServerVar = 42 %>
> ......
> The following line of HTML was generated on the client to print the value
of
> a client variable into the page after the page was sent to the browser.
The
> value of the client variable has been set equal to the value of the server
> variable printed above.
> <BR>
> <BR>
> <SCRIPT LANGUAGE = "JavaScript">
> <!--
> var x ;
> x = <%= strMyServerVar %> ;
> if (x == <%= strMyServerVar%>) {
> document.write ("<STRONG>The value of the client variable is " + x +
> ".</STRONG>")
> }
> //
> -->
> </SCRIPT>
Thanks all

The rec from S. Justin Gengo works fine. I felt there was a simple way.

Bob T

"Bob T" <twick10@.hotmail.com> wrote in message
news:e9G7ajs1DHA.2604@.TK2MSFTNGP09.phx.gbl...
> Hi All,
> I am trying to pass a variable from my VB asp.net script (from for example
> Sub Page_Load in mypage.aspx.vb) to my Client side script.
> I have found and looked at a very good example "Client and Server
Scripting
> in Web Pages" but it only shows server side scripting that is written in
> HTML in mypage.aspx and not script from mypage.aspx.vb. How can I pass a
> variable value from mypage.aspx.vp to my client side script?
>
> Sample from "Client and Server Scripting in Web Pages"
> <%@. LANGUAGE="VBSCRIPT" %>
> <HTML>
> <HEAD>
> <META NAME="GENERATOR" Content="Microsoft Visual InterDev 1.0">
> <META HTTP-EQUIV="Content-Type" content="text/html; charset=iso-8859-1">
> <TITLE>Document Title</TITLE>
> </HEAD>
> <BODY>
> <% Dim strMyServerVar
> strMyServerVar = 42 %>
> ......
> The following line of HTML was generated on the client to print the value
of
> a client variable into the page after the page was sent to the browser.
The
> value of the client variable has been set equal to the value of the server
> variable printed above.
> <BR>
> <BR>
> <SCRIPT LANGUAGE = "JavaScript">
> <!--
> var x ;
> x = <%= strMyServerVar %> ;
> if (x == <%= strMyServerVar%>) {
> document.write ("<STRONG>The value of the client variable is " + x +
> ".</STRONG>")
> }
> //
> -->
> </SCRIPT>