|
-
Apr 26th, 2009, 12:10 PM
#1
Thread Starter
Addicted Member
[RESOLVED] Why Isn't This Code Working?
Hi, I have this code, which works perfectly the first time I click a button:
Code:
private void button3_Click(object sender, EventArgs e)
{
webBrowser1.Navigate(new Uri("about:blank"));
webBrowser1.Document.Write("<table id=\"table\" border=\"1\" cellspacing=\"1\" cellpadding=\"1\">");
for (int r = 0; r <= (numericUpDown1.Value - 1); r++)
{
webBrowser1.Document.Write("<tr>");
for (int c = 0; c <= (numericUpDown2.Value - 1); c++)
{
webBrowser1.Document.Write("<td> </td>");
}
webBrowser1.Document.Write("</tr>");
}
webBrowser1.Document.Write("</table>");
But when I click the button a second time, the browser control just displays a blank page, regardless of whether the numericUpDown values are changed.
-
Apr 26th, 2009, 12:50 PM
#2
Frenzied Member
Re: Why Isn't This Code Working?
Where is this writing too? I mean is it at the end of the file or the top of the file (I presume end) how does your program know your not writing after the <\body> tag?
-
Apr 26th, 2009, 01:21 PM
#3
Thread Starter
Addicted Member
Re: Why Isn't This Code Working?
This writes to the page about:blank in a webBrowser control.
It looks like this goes after the </html> tag, and works perfectly the first time, but the second time, it's just a blank page, with the about:blank source code, and it won't insert my table generating code.
-
Apr 26th, 2009, 02:03 PM
#4
Frenzied Member
Re: Why Isn't This Code Working?
And what are you trying to do, generate a web page?
-
Apr 26th, 2009, 03:19 PM
#5
Re: Why Isn't This Code Working?
If you just want to generate a dynamic HTML page, theres no reason to navigate to about:blank first, just assign the HTML to the WebBrowsers DocumentText property:
Code:
StringBuilder htmlBuilder = new StringBuilder();
htmlBuilder.Append("<table id=\"table\" border=\"1\" cellspacing=\"1\" cellpadding=\"1\">");
for (int r = 0; r <= (numericUpDown1.Value - 1); r++) {
htmlBuilder.Append("<tr>");
for (int c = 0; c <= (numericUpDown2.Value - 1); c++) {
htmlBuilder.Append("<td> </td>");
}
htmlBuilder.Append("</tr>");
}
htmlBuilder.Append("</table>");
webBrowser1.DocumentText = htmlBuilder.ToString();
-
Apr 26th, 2009, 03:58 PM
#6
Thread Starter
Addicted Member
Re: Why Isn't This Code Working?
Thanks Atheist, your code did exactly what I needed to accomplish!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|