I need help. How can i select a dropdown item that does not have the selected attribute in C# using Webkit? The html is :
<select id="question" name="questionId">
<option value="">Text</option>
<option value="1">
Question 1
</option>
<option value="2">
Question 2
</option>
</select>
Related
I have an ASP.NET Core 2.0 web application that generates a multi-select list box using bootstrap-multiselect (basically a prettied up list box control)
The code generated is shown:
<select class="multiselect-ui form-control" id="Issues" multiple="multiple" name="Issues">
<option selected="selected" value="1">Dilapidated Structures</option>
<option selected="selected" value="3">Junk on Premises</option>
<option selected="selected" value="4">Junk Vehicles</option>
<option selected="selected" value="5">Minor Maintenance</option>
<option selected="selected" value="6">Miscellaneous</option>
<option selected="selected" value="7">Overgrowth</option>
<option selected="selected" value="8">Right of Way</option>
<option selected="selected" value="9">Sidewalks</option>
<option selected="selected" value="10">Trash</option>
<option selected="selected" value="2">Weeds/High Grass</option>
</select>
When this is submitted in a form, I see the Issues being added to the URL like so:
/Cases?Issues=1&Issues=3&Issues=4&Issues=5 ...
This is great and I am able to retrieve the values in my controller using a List<string> object. My question is, how would I add a hyperlink to the page that uses the values already sent via GET? Basically I would like to use Tag Helpers, but there is no way to add an array of values that I've found. There are dictionary key/pairs, but of course you are not able to add multiple values with the same key. I would like to be able to reference a List<string> in the tag helper itself (the following does not work, but should give an idea of what I'm after if I am sending the List<string> back using ViewBag):
<a asp-route-Issues=#ViewBag.IssuesList>Next</a>
I found out through this link that this feature isn't implemented. I used #Url.Action to build my link as shown (where ViewBag.IssuesList contains the List<string> -- I also left out some paramters for brevity:
Previous
Im working a web browser automation project.
this is exampel code ;
<select name="ctl00$ctl00$main$Content$cbReceiverCity" id="ctl00_ctl00_main_Content_cbReceiverCity" tabindex="40" class="custom-select" onchange="javascript:GetTowns(this);void(0);" style="width:170px;" size="5">
<option selected="selected" value="-1">-- choose one --</option>
<option value="1">Portugal</option>
<option value="2">Spain</option>
<option value="3">France</option>
<option value="4">Germany</option>
<option value="5">Italy</option>
</select>
and my c# code;
HtmlElement enter =
webBrowser1.Document.GetElementById("ctl00_ctl00_main_Content_cbReceiverCity");
enter.SetAttribute("selectedIndex", "5");
enter.InvokeMember("onchange");
but,Index value does not change. How can I change this?
Replace this
enter.SetAttribute("selectedIndex", "5");
with this
enter.Children[5].SetAttribute("selected", "selected");
where 5 is the index of the option you want to select
I have code Html as following:
<select name="film_episode">
<option value="1111">Post 1</option>
<option value="2222">Post 2</option>
<option value="3333">Post 3</option>
</select>
how to use 'webbrowser' in c# click on selected automatically 'Post 2'.
Please help me. Thank you very much.
Use this to get things easier
<select runat="server" id="dropDownList1" name="film_episode">
<option value="1111">Post 1</option>
<option value="2222">Post 2</option>
<option value="3333">Post 3</option>
</select>
in Code behind(aspx.cs)
dropDownList1.Items.FindByText("Post 2").Selected = true;
I would like to modify the selected value of my dropdownlist without have to click on my dropdownlist.
I already tried this line with JQuery:
$('#select-nb-Persons-button').children(":first").text("3");
It printed well "3" for the dropdownlist but after, when I clicked on the dropdownlist, I noticed that it is always the first option tag that is selected and not the third option tag as I want. :
Code created by razor for the dropdownlist :
<div class="ui-select">
<div id="select-nb-Persons-button" class="ui-btn ui-icon-carat-d ui-btn-icon-right ui-corner-all ui-shadow">
<span>1</span>
<select data-val="true" data-val-number="Le champ nbPersons doit ĂȘtre un nombre." data-val-required="Le champ nbPersons est requis." id="select-nb-Persons" name="nbPersons">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
</select>
</div>
</div>
Can you help me please ?
Thank you
You can use val() to set the selected item in a select. To select the item with a value of 3, try this:
$('#select-nb-Persons').val('3');
Try below code.
$('#select-nb-Persons-button').children('select').val('5');
DEMO here
How do I create a postback with a onchange while getting the value into a Request[]
The code:
<select name="nameOnSelection" id="idOnSelection" onchange="">
<option value="1">
random string
</option>
<option value="2">
random string
</option>
</select>
Im coding in cshtml. and im not looking for JSON solution.
Using jQuery you can easily find the closest <form> tag and submit it.
<select onchange="$(this).closest('form').submit();"/>