none
webBrowser documentText issue

    Domanda

  • Hello,  in my application I have my beatiful WebBrowser control,
    in the middle of my application i wrote a Menu page using
    myBeatifulWB.DocumentText = "HTML CODE";
    then once i click on a special link (eg. customProtocol://) I need to refresh my page to a new one,
    so i handle this


    Code Snippet

    private void myBeautifulWB_Navigating(object sender, WebBrowserNavigatingEventArgs e) {
                if (e.Url.ToString().IndexOf("customProtocol:") != -1) {               
                    e.Cancel = true;
                        BOL.CustomBrowser.handle(e.Url.ToString(), this);
    }
    }


    this actually work the first time (where i set the menu)
    but here I found the issue, seems that DocumentText can be set only once,
    googling(yahooing and livesearching) around,
    i found a pair of solution on Windows form, not useful on PPC,

    1) setting AllowNavigation
    there is no Webbrowser.AllowNavigation Property
    2)
    WebBrowser.Document.OpenNew(true);
    there is no Document property

    Please, note that i can't use a temporary file and Navigate() to it.
    is there  a workaround to this?
    lunedì 11 giugno 2007 07:35

Risposte

  • i don't know, in the os. image i have it work out of the box without the prompt you're talking about.

    probably is in IE security setting,

    as I already told the first time it work, after that documentText do nothing.

     

    lunedì 18 giugno 2007 08:17

Tutte le risposte

  • i do a very ugly workaround to this,

    what i do is simply substitute the webBrowser control with a new one

     

    Very ugly code

    private bool _setHTML = false;

    public void showHTML(string html) {

     if(!_setHTML){
      this.myBeautifulWB.DocumentText = html;
      _setHTML=true;
     }else{
      this.Controls.Remove(this.myBeautifulWB);
      this.myBeautifulWB.Dispose();
      this.myBeautifulWB= new WebBrowser();
      
      //... setting webbrowser properties
      
      this.Controls.Add(this.myBeautifulWB);
      this.myBeautifulWB.DocumentText = html
     }
    }

     

     

    lunedì 11 giugno 2007 09:37
  • nobody knowns another better solution?

    this one is slow and you have to handle the history , and everytime you go back you have to reload

    the page..

     

     

     

    martedì 12 giugno 2007 14:15
  • I saw this on another Forum :

     

    Code Snippet

    if (webBrowser1.Document != null)
    {
        webBrowser1.Document.OpenNew(true); 
        webBrowser1.Document.Write("New HTML Code");
    }
    else
    {
        webBrowser1.DocumentText = "HTML Code";
    }

     

    And it worked for me...

     

    Pawa

    giovedì 14 giugno 2007 13:33
  • Quote of first post
    2)WebBrowser.Document.OpenNew(true);
    there is no Document property

    In compact framework there is no Document property, I think this can be solved only with a patch(

    eg. exposing AllowNavigation

    ) from MS.

     

    venerdì 15 giugno 2007 11:08
  • Hi, how do you have things set up to use a customProtocol:// ?  I tried that myself, but I would always get a popup saying something about an unsecure webpage.

    Back to your problem, what exactly happens when you change your DocumentText?  In my app I also have a WebBrowser control in the middle which I populate via HTML code from a database.  I can switch the DocumentText of the WebBrowser control without any problems.  Here's my code:

                // Build the HTML to show up for this step
                string startHTML = "<html><head></head><body>";
                string endHTML = "</body></html>";

                // Get the HTML text from the indication
                string strHTML = startHTML + m_indication.Steps[nStep].HTML + endHTML;

                 // Switch the HTML page
                this.webBrowserStepInfo.DocumentText = strHTML;

    This is done without reloading the control, or reloading the form.

    domenica 17 giugno 2007 18:15
  • i don't know, in the os. image i have it work out of the box without the prompt you're talking about.

    probably is in IE security setting,

    as I already told the first time it work, after that documentText do nothing.

     

    lunedì 18 giugno 2007 08:17