-3

I'm trying to automate html events using c#.
I have html dropdown and on change of its value it shows/hides specific divs.
Below is sample HTML code.

<!DOCTYPE html>
<html>
<body>
<select id="ddl">
    <option value="1" selected="selected">TextBox</option>
    <option value="2">Button</option>
  </select>

<input style="display: none" type="text" class="textboxclass" />

<div class="btn" style="display: none">
    <button type="button">Submit</button>
</div>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$('#ddl').change(function()
{var name = $('#ddl option:selected').text();
var id = $('#ddl option:selected').val();
if(id =="1"){$('.textboxclass').show();$('.btn').hide();}
else{$('.textboxclass').hide();$('.btn').show();}});
</script>

</body>
</html>

I'm using mshtml.dll to read the HtmlDocument and I have to fire "change" event programmatically. Tried different ways like below ones:

HTMLOptionElement drpelem.select=true;
HTMLSelectElement elem.click();


But it's not working. Please guide me.

  • you can use jQuery to perform change event, like this `$('#ddl').trigger('change')` or `$('#ddl').change()` – Bhaumik Pandhi Aug 24 '17 at 12:40
  • I need to trigger event through c# code. i tried using .fireevent("onchange") it is working for javascript calls. But the same is not working for jquery $().change() event. – Sruthi Neelam Aug 24 '17 at 12:42

1 Answers1

0

I think this question was already asked and answered in a different form, here: https://stackoverflow.com/a/1456714/19020 or here: https://stackoverflow.com/a/11175179/19020 -- since mshtml is used by Internet Explorer.

But really, to load a full browser experience you'll need to load an ActiveX control, or COM control or whatever they're called by Microsoft nowadays. As far as I know, mshtml.dll just renders the HTML.

Dan Esparza
  • 28,047
  • 29
  • 99
  • 127