Skip to content

Changing value of control defined in HTML file

pedram

Asked Apr 3, 2013, 9:20 PM EDT1 answer
Share
LinkedInX
I've been trying to change the value of a checkbox control defined in an html file,this html file is shown in a webbrowser control and the webbrowser itself is defined as a user control in C#
I am willing to set the value of the checkbox control  (defined  in the html file and user control) from the form that contains my usercontrol
The related code in user control:
C#
        public bool _checkBoxProperty
        {
            set
            {
                if (webBrowser1.Document != null && webBrowser1.Document.GetElementById("Checkbox1") != null)
                {
                    bool s = false;
                    string chpro = webBrowser1.Document.GetElementById("Checkbox1").GetAttribute("checked").ToString();
                    if (chpro == "false")
                        s = false;
                    s = value;
                    webBrowser1.Document.GetElementById("Checkbox1").SetAttribute("checked", value.ToString());
                }
            }
            get
            {
                if (webBrowser1.Document != null && webBrowser1.Document.GetElementById("Checkbox1") != null)
                {
                    {
                        string bls = webBrowser1.Document.GetElementById("Checkbox1").GetAttribute("checked");
                            return Convert.ToBoolean(bls);
                    }
                }
                else
                    return false;
            }
        }

this piece of code brings the checkbox property in my form and I can set its value,but when I run the program it resets itself to null,
I've been working on this piece of code for days and I fully appreciate some help :)

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    Fortunately I found the issue myself,I should've raised an event
    here is the code in case someone needs it
    usercontrol:
    C#
            public delegate void ThisLoadEventHandler(object sender, EventArgs e);         public event ThisLoadEventHandler ThisLoad;           void OnThisLoad()         {             if (ThisLoad != null)                 ThisLoad(this, new EventArgs());         } 
            private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)         {             OnThisLoad();         } 
            public webctrl1()         {             InitializeComponent();             OnThisLoad();         } In the main form:
            private void defultstart()         {             webctrl11._radioBoxProperty = "false";             webctrl11._checkBoxProperty = false;             webctrl11._textageProperty = "Age";             webctrl11._textnameProperty= "Name";             webctrl11._listBoxProperty = "<SELECT id=Select1  name=drop1> <OPTION value=0></OPTION> <OPTION value=1>item 3</OPTION> <OPTION value=2>item 4</OPTION></SELECT>";         } 
            private void webctrl11_ThisLoad(object sender, EventArgs e)         {            defultstart();         }
    0