Is there a way of getting the asp:DropDownList bound items to display the output inline rather than with linebreaks, I currently have around 1000+ items bound to a DropDownList multiple times which is causing so many lines in the HTML & causing the page to load slowly
What currently displays (Short Version)
<select name="randomName" onchange="randomOnChane" id="randomId">
<option value="42">Test</option>
<option value="43">Test</option>
<option value="44">Test</option>
<option value="45">Test</option>
<option value="46">Test</option>
<option value="47">Test</option>
<option value="48">Test</option>
<option value="49">Test</option>
<option value="50">Test</option>
<option value="51">Test</option>
</select>
What I'd like
<select name="randomName" onchange="randomOnChane" id="randomId">
<option value="42">Test</option><option value="43">Test</option><option value="44">Test</option>
<option value="45">Test</option><option value="46">Test</option><option value="47">Test</option>
<option value="48">Test</option><option value="49">Test</option><option value="50">Test</option>
<option value="51">Test</option>
</select>
1000+ items in a dropdown list? No wonder your page is loading slowly. Minifying your HTML won't make much difference performance wise. You should look at a "auto complete" functionality, such as http://jqueryui.com/autocomplete/.
Also as a user i won't be happy to scroll through a list with more then 1000+ items :)
You can inherit the control then intercept the rendered HTML and filter it, like so
class MyLinelessWebControl: System.Web.UI.WebControls.DropDownList()
{
protected override RenderControl(HtmlTextWriter writer)
{
StringWriter sw = new StringWriter();
HtmlTextWriter tempWriter = new HtmlTextWriter(sw);
base.RenderControl(tempWriter);
writer.Write(sw.ToString().Replace("\r\n",""));
}
}
That being said, I doubt the removal of newline characters will improve performance much.
Related
Good morning.
I can not select an item from the drop-down list.
Did the following:
1) I entered the text
WebBrowser1.Document.GetElementById ("Advert_category_id").InnerText = "Wedding / Event Services";
2) Set the value using the following commands, in different sequences, as soon as not twisted.
WebBrowser1.Document.GetElementById("Advert_category_id").SetAttribute("selected", "selected");
WebBrowser1.Document.GetElementById("Advert_category_id").InvokeMember("onchange");
WebBrowser1.Document.GetElementById("Advert_category_id").InvokeMember("submit");
WebBrowser1.Document.GetElementById("Advert_category_id").InvokeMember ("value", "84");
The problem is that this code selects the option I need, but it does not appear in the field. Those. Only when you click on the field, after executing the code, you can see that the desired option is selected. But this approach is also not true, because
The following drop-down list named SUB CATEGORY does not load the required data (the data remains with the category selected by default - Professional)
3. I tried to experiment with different id-shniki. Nothing helps :(
The site itself https://list.asiandirectoryapp.com/advert/create
(You must register to view)
I made the second ack,
That would not waste time for registration
fovogaze#p33.org
qwerty123
The code of interest
<div style="display:none"><div class="form-group"><label class="control-label" for="Advert_city_id">City</label><select class="form-control" name="Advert[city_id]" id="Advert_city_id">
</select><div class="help-block error" id="Advert_city_id_em_" style="display:none"></div></div></div><div class="form-group"><label class="control-label required" for="Advert_category_id">Category <span class="required">*</span></label><select class="form-control" name="Advert[category_id]" id="Advert_category_id">
<option value=""></option>
<option value="35">Beauty, Health & Fitness</option>
<option value="19">Education</option>
<option value="21">Entertainment</option>
<option value="27">Food, Drink & Sweet Centres</option>
<option value="39">Home Services</option>
<option value="116">Jobs/Careers</option>
<option value="43">Motoring</option>
<option value="50">Other Services</option>
<option value="1">Professional</option>
<option value="51">Property Improvements</option>
<option value="84">Wedding/Event Services</option>
<option value="117">Whats On Guide</option>
</select><div class="help-block error" id="Advert_category_id_em_" style="display:none"></div></div><div class="form-group"><label class="control-label required" for="Advert_categoryList">Sub category <span class="required">*</span></label><select multiple="multiple" class="form-control" name="Advert[categoryList][]" id="Advert_categoryList">
<option value="2">Accountants</option>
<option value="4">Claims</option>
<option value="123">Clothing Manufacturers</option>
<option value="6">Estate & Letting Agents</option>
<option value="7">Finance/Mortgages</option>
<option value="8">Graphic & Web Design</option>
<option value="9">Immigration</option>
<option value="10">Information Technology</option>
<option value="11">Insurance</option>
<option value="13">Mobile Apps - Mobile Phones</option>
<option value="14">Online Marketing/ SEO</option>
<option value="18">Print</option>
<option value="15">Retail and Wholesale</option>
<option value="16">Solicitors - Lawyers</option>
<option value="17">Travel Agents</option>
</select><div class="help-block error" id="Advert_categoryList_em_" style="display:none"></div></div><div class="form-group"><label class="control-label required" for="Advert_name">Company Name <span class="required">*</span></label><input class="form-control" placeholder="Company Name" name="Advert[name]" id="Advert_name" type="text" maxlength="100" /><div class="help-block error" id="Advert_name_em_" style="display:none"></div></div>
P.S. I can fill out all the fields, press the buttons the same way, but with the drop-down list the trouble. Thank you for any help.
I had a similar problem but I chose to solve it by simply invoking a client-side javascript (with a parameter) that handles the manipulation of the dom objects.
I found that this way I can separate code too, keeping dom handling in the JS and application-code in the winforms. Itll also allow you to leverage any functionality provided by e.g. jQuery plugins wrapping the select.
It could look like this (not tested):
Object[] objArray = new Object[2];
objArray[0] = selectorID;
objArray[1] = valueToSet;
webBrowser1.Document.InvokeScript("SetSelector", objArray);
and in the client side:
function SetSelector(selectorID, valueToSet){
$('#'+selectorID).val(valueToSet); //or any function you'd like
}
I am trying to create a multiple choice select field in my .cshtml file that looks like this:
<select multiple="multiple" id="select-multiple" style="width:500px" name="MultipleSelect">
<option value="1">option 1</option>
<option value="2">option 2</option>
<option value="3">option 3</option>
<option value="4">option 4</option>
</select>
I have a model that has a List<string> MultipleSelect that maps perfectly when i save my model. all the selected values get to the controller and are saved in the database. But when the page reloads the values don't show. I checked with the debuger and the MultipleSelect list gets filled with the values before the view gets loaded.
Should I use a diferent type for my MultipleSelect value or is this just not the right way to do this?
Im trying to write an application where web form will be filled with one click. The problem is that I can't get working picking one option from listbox, here is HTML code I'm facing:
<select name="data[PvpnetAccount][date_of_birth_day]" id="PvpnetAccountDateOfBirthDay" class="ignore_keyup c-signup__input c-signup__input--select c-form-group__input c-form-group__input--select js-selectize">
<option value="" disabled selected >Day</option>
<option value="01">1</option>
<option value="02">2</option>
<option value="03">3</option>
<option value="04">4</option>
<option value="05">5</option>
<option value="06">6</option>
<option value="07">7</option>
<option value="08">8</option>
<option value="09">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
</select>
I have tried with different options, but nothing gave me results so far, so I'm up for any suggestions. My first try was:
webBrowser1.Document.GetElementById("PvpnetAccountDateOfBirthDay").SetAttribute("value", "03");
However Im aware that it won't work.
EDIT:
A guy advised me to do this like this:
var daySelect = WebBrowser1.Documents.GetElementById("PvpnetAccountDateOfBirthDay");
var day10Option = daySelect.Children.Single( e => e.Value == "10" );
day10Option.SetAttribute("selected", "selected");
However it seems like .Single gives me error.
Just as a precaution for test purposes to make sure that page loaded correctly and you got correct element selected look at outerHTML property of the element. Also, are you executing this code on background worker, if yes you will need to use Action let me know if you need more instructions on that. Also try using IHTMLSelectElement instead of HtmlElement. To use it add reference to
Microsoft.mshtml
and add using mshtml; to your file. After you can do the following:
HtmlElement tmp = webBrowser1.Document.GetElementById("PvpnetAccountDateOfBirthDay");
IHTMLSelectElement tComboBox = (IHTMLSelectElement)tmp.DomElement;
tComboBox.selectedIndex = 2;
Hope that helps.
Html code/example of dropdown:
<select class="ng-valid ng-dirty ng-touched" style="max-width: 235px" ng-model="blogerj" ng-options="blogerj.long_name for blogerj in blogerj track by blogerj.id">
<option class="" value="">[Choose...]</option>
<option label="label 1" value="1">Text Content 1</option>
<option label="label 2" value="2">Text Content 2</option>
<option label="label 3" value="3">Text Content 3</option>
<option label="label 4" value="4">Text Content 4</option>
</select>
If I just set attribute making it selected then it dont work because button for submit appears only when element is selected.
I also tried just to click element to open dropdown and then again click desired option but again it gave me no results.
foreach (GeckoHtmlElement geckoHtmlElement in gwBrowser.Document.GetElementsByTagName("select"))
{
if (geckoHtmlElement.GetAttribute("class") == "ng-valid ng-dirty ng-touched")
{
geckoHtmlElement.Click();
}
}
Actually it finds element but clicking dont do anything.
So maybe there is any fancy js method to select that dropdown?
From the portion class="ng-valid ng-dirty ng-touched" it looks like there is AngularJS at work here - because angular usually uses the prefix ng-. Angular can intercept user actions and take control of how your web page controls behave.
i have some existing code, and i wonder what kind of country codes they are?
Are the somehow mappable to codes somewhere in the .NET framework?
<option value="4">Albania</option>
<option value="7">Andorra</option>
<option value="21">Anguilla</option>
<option value="1">Antigua And Barbuda</option>
<option value="23">Argentina</option>
<option value="59">Aruba</option>
<option value="66">Australia</option>
<option value="390">Austria</option>
<option value="463">Bahamas</option>
<option value="477">Bahrain</option>
<option value="479">Barbados</option>
<option value="491">Belarus</option>
<option value="493">Belgium</option>
<option value="525">Belize</option>
<option value="529">Bolivia</option>
<option value="541">Bosnia Herzegovina</option>
I suspect those codes represent an arbitrary key in a database somewhere, not a standard country code.
http://countrycode.org/
Ian
Extract the content from this table: http://countrycode.org/, perhaps storing it as a comma delimited file. Then, in your application, look up the code associated with the country. Note: the copyright on the table is for personal noncommercial use only. http://countrycode.org/copyright