Jeffrey Rasmussen
Jeffrey Rasmussen

Reputation: 393

Change date value in RadDatePicker in WebBrowser

I need to change date value and then continue doing some actions on the webpage using Webbrowser control in C#.

Here is the way I add my custom JS function to webpage and then call it:

        HtmlElement head = webBrowser1.Document.GetElementsByTagName("head")[0];
        HtmlElement scriptEl = webBrowser1.Document.CreateElement("script");
        IHTMLScriptElement element = (IHTMLScriptElement)scriptEl.DomElement;

        element.text = "function SelectDate1() { " +
        "var frames = window.frames; " +
        "for (var i = 0; i < frames.length; i++) { " +
        "var calendar = frames[i].document.getElementById('ctl00_ContentPlaceHolder1_RadDatePicker1'); " +
        "} " +
        "}";

        head.AppendChild(scriptEl);
        webBrowser1.Document.InvokeScript("SelectDate1");

But I need to use $find('<%= RadDatePickerName.ClientID %>') to find this control and then call selectDates on it. But find method returns NULL. What is wrong here? Please help.

Upvotes: 0

Views: 586

Answers (1)

Faraday
Faraday

Reputation: 2954

This should solve it:

window.frames[0].$find('ctl00_ContentPlaceHolder1_RadDatePicker1').set_selectedDate(new Date('2020/10/12'))

Upvotes: 1

Related Questions