CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2010
    Posts
    34

    Exclamation Javascript HtmlElement Click Event problem?!

    So I was porting an app to a clean project in VS. This is .net 3.5, VS2008.
    Background:
    General click here, click there type stuff in a webbrowser1.
    I noticed that I get to one location that results in the user clicking a SPAN element, and then it didn't work. It was like the user hit back and went to the previous page. (It is the main page of the site) buuuuut... The click works if I add this to the element click event. If I just subscribe to the element click handler, it bombs out and does what I described above.
    But this is what I have to do inside the click event, that allows the web page to work properly. I know it's javascript, is there a way to tell if any AJAX is involved? I've never seen something like this.
    Any thoughts would be appreciated, it took me around 16 hours to pinpoint it was the 2 lines below I NEED in the click event. If I leave the click event empty, the web page bombs out....
    (this is just a dump of what's in the Form1 public partial class)
    I literally just made a form app, add wb1, and navigate on form load to the page sign in...
    But it only works if I have the below 2 lines?! GAH!
    I'm not looking for another way to do it, I have a feeling it's some weird fundamental of the site, but this makes no sense...

    string[] currentelements = new string[22];
    public int mouseclickcntr = 0;
    public Form1()
    {
    InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
    webBrowser1.Navigate("URL REMOVED");
    }
    private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
    {
    foreach (HtmlElement el in webBrowser1.Document.All)
    {
    el.Click -= new HtmlElementEventHandler(el_Click);
    el.Click += new HtmlElementEventHandler(el_Click);
    }
    }
    private void el_Click(object sender, HtmlElementEventArgs e)
    {
    currentelements[mouseclickcntr] = "DOUBLEYOUTEE-EFF"; // THIS MUST BE HERE, CAN'T MAKE THE INDEX STATIC
    mouseclickcntr += 1; // THIS ALSO MUST BE HERE TO ALLOW THE ABOVE LINE TO WORK
    }
    Last edited by kungpaoshizi; January 24th, 2011 at 05:39 PM. Reason: URL REMOVIN

  2. #2
    Join Date
    Nov 2010
    Posts
    34

    Re: Javascript HtmlElement Click Event problem?!

    Lol, thinking about how crazy this sounds, I'm still pondering over what this possibly does in memory that could alleviate a "bug" in the web page? Only one element I've found on this web page requires the above statement within the click event, whereas all other elements work just fine with the below. And then as I was stating above, the below causes the element to not process correctly, and instead of the text link that is supposed to populate the text box, it straight falls out of the page it's in, and loads the main start page of the system.


    private void el_Click(object sender, HtmlElementEventArgs e)
    {
    }

    Yes, an empty handler on an element click causes a failure on the page.. heh (SPAN element specifically)
    But of course if I DON'T subscribe to the click event it works fine.

    Thanks again for any thoughts, they are GREATLY appreciated!

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

Featured