Results 1 to 6 of 6

Thread: [RESOLVED] Why Isn't This Code Working?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2006
    Posts
    219

    Resolved [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>&nbsp; &nbsp; &nbsp; &nbsp;</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.

  2. #2
    Frenzied Member
    Join Date
    Jul 2008
    Location
    Rep of Ireland
    Posts
    1,380

    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?

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jul 2006
    Posts
    219

    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.

  4. #4
    Frenzied Member
    Join Date
    Jul 2008
    Location
    Rep of Ireland
    Posts
    1,380

    Re: Why Isn't This Code Working?

    And what are you trying to do, generate a web page?

  5. #5
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    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>&nbsp; &nbsp; &nbsp; &nbsp;</td>");
                    }
                    htmlBuilder.Append("</tr>");
    
                }
                htmlBuilder.Append("</table>");
    
                webBrowser1.DocumentText = htmlBuilder.ToString();
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Jul 2006
    Posts
    219

    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
  •  



Click Here to Expand Forum to Full Width