-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.

2
  • you can use jQuery to perform change event, like this $('#ddl').trigger('change') or $('#ddl').change() Commented Aug 24, 2017 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. Commented Aug 24, 2017 at 12:42

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.