简体   繁体   中英

web page doesn't recognize text has been entered in textbox

So I'm setting the value of a textbox, then I'll click a button to submit the search. The value in the textbox is showing what I want, but when I trigger the click of the button, the website gives me an error message on the page as if the textbox value is empty (even though I'm looking at it and it's showing what I wanted).

Now if I manually click on the button, it still thinks the textbox is empty. But if I manually click on the textbox (just click, don't change anything), then manually click on the button, it works.

So apparently there's something happening behind the scenes that requires the textbox to have had the focus before the page will recognize what's been typed in.

    private void SetText(string elementID, string text)
    {
        foreach (HtmlWindow hw in this.webBrowser1.Document.Window.Frames)
        {
            HtmlElement element = hw.Document.GetElementById(elementID);
            if (element != null)
            {
                element.SetAttribute("value", text);
                // here's where I'm trying things
                break;
            }
        }
    }

Here's what I've tried (not sure all of these were even valid things, but I tried them anyway:

I've tried setting the focus on the textbox and then removing it by setting it on the button -- element.Focus() and then button.Focus() before clicking the button.

I've tried invoking the changed event -- element.InvokeMember("change"), element.InvokeMember("changed"), element.InvokeMember("onchange"), element.InvokeMember("textchanged").

I've tried invoking the focus event -- element.InvokeMember("focus").

I've tried invoking the lostfocus event -- element.InvokeMember("lostfocus").

I have no idea what it is that the webpage is expecting to be triggered when someone actually types into the textbox, but it's apparently preventing the page from "seeing" what's been placed in there by my code.

Any ideas?

Turns out there were 3 textboxes (each with a slightly different name) that are somehow interconnected. The value of all 3 must be set before the button will work properly. I thought I'd tried that, but perhaps I didn't do all 3 before, or maybe I had them in the wrong order. Ugh.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM