I have a TextBox with an Ajax Control Toolkit AutoCompleteExtender, and I'm having some issues with the formatting.
If I omit the CompletionListCssClass, CompletionListItemCssClass, CompletionListHighlightedItemCssClass values, it displays fine. But I just need to align the autocomplete text to the left, and the size of the TextBox.
If I set these values in the site.css:
.autocomplete_listItem
{
background-color: #222;
color: #cfdbe6;
}
.autocomplete_highlightedListItem
{
background-color: #999;
color: #111;
}
.autocomplete_completionListElement
{
}
then I bullets on the list.
How do I make the bullets not show, align the list to be right under the TextBox, the list items left aligned, and the size to match the TextBox?
All you need to do to remove the bullets is add list-style-type:none to each of your classes:
.autocomplete_listItem
{
background-color: #222;
color: #cfdbe6;
list-style-type:none;
}
.autocomplete_highlightedListItem
{
background-color: #999;
color: #111;
list-style-type:none;
}
.autocomplete_completionListElement
{
list-style-type:none;
}
This is because the autocomplete results are returned as a bulleted list by the AJAX extender - so if you customize the style, you need to make sure and hide those bullets.
In order to tell you how to align it properly with other elements, I would need to see your markup (which is not included in your question).
Related
I have a Label in my .net page which I am trying am dynamically adding text to. What I would like to do is add part of the text in green, and part in red.
The control in the page is set to forecolor=green.
I'm adding text through a stringbuilder, e.g
bodyText.Append("</br>");
bodyText.Append( startDate.ToShortDateString() + " - " + endDate.ToShortDateString());
Now I wish to append some more text, although in red rather than green.
Is it possible to do the the same Label? Or does it need to be a separate Label side by side?
This is untested, but something like this should work.
<span class="blue">First</span>
<span class="red">Word</span>
CSS
.blue
{
display: inline;
color: blue;
}
.red
{
display: inline;
color: red;
}
Have you tried adding markup when you add the texts meant to be red? Something like
bodyText.Append("<span style='color:red'>" + startDate.ToShortDateString() + " - " + endDate.ToShortDateString() + "</span>");
I have an ASP.NET application and I create dynamically several combo boxes with AjaxControl Toolkit. All combo boxes are filled up with data but some don't show the data.
Here is my code :
cbo = new AjaxControlToolkit.ComboBox();
cbo.ID = string.Format(CultureInfo.GetCultureInfo("fr-FR"), "cbo{0}", RemoveSpecialCharacters(filter.Key)); // filter.key is the name of the combo
cbo.AutoCompleteMode = AjaxControlToolkit.ComboBoxAutoCompleteMode.SuggestAppend;
cbo.AutoPostBack = true;
cbo.Visible = true;
cbo.MaxLength = 500;
cbo.DataSource = GetFilterData2(requestId, filter.Key); // loads the data source with a list<string>
cbo.DataBind();
cbo.ItemInserted += this.CboItemInserted;
this.cboFilters.Add(cbo);
li.Controls.Add(cbo); // combo is added to the list item
when I inspect my HTML page with Chrome, I get for the combo which works:
<ul id="MainContent_cboScanner_cboScanner_OptionList" class="ajax__combobox_itemlist" style="visibility: hidden; z-index: 1000; overflow-x: hidden; overflow-y: auto; width: 213px; position: absolute; height: 464px; left: 334px; top: 242px; display: none;">
And for the one which doesn't display its items :
<ul id="MainContent_cboEnvironnement_cboEnvironnement_OptionList" class="ajax__combobox_itemlist" style="display:none;visibility:hidden;">
Why an AjaxControlToolkit combobox would not display its items despite having them?
All comboboxes after a bad textbox which had a space in the Id didn't show its items.
I added the Remove-special-characters method on all textboxes and the problem was solved.
Here is what I added:
txt = new TextBox();
txt.ID = string.Format(CultureInfo.GetCultureInfo("fr-FR"), "txt{0}", RemoveSpecialCharacters(filter.Key));
Here is my method:
private static string RemoveSpecialCharacters(string mystring)
{
return mystring.Trim().Replace(' ', '_').Replace("'", "_").Replace("(", string.Empty).Replace(")", string.Empty).Replace("/", string.Empty).Replace(#"\", string.Empty);
}
I searched for some time on this question and couldn't find a working answer anywhere.
I have an asp DropDownList that gets disabled and enabled based on whether the form is in view mode or not. The problem I was having is when the DropDownList.Enabled = false the text is hard to read(grey on lightgrey).
I solved the issue by passing the DropDownList to some methods.
public void DisableDDL(ref DropDownList DDL)
{
DDL.BackColor = System.Drawing.Color.LightGray;
foreach (ListItem i in DDL.Items)
{
if (i != DDL.SelectedItem)
{
i.Enabled = false;
}
}
}
public void EnableDDL(ref DropDownList DDL)
{
DDL.BackColor = System.Drawing.Color.White;
foreach (ListItem i in DDL.Items)
{
i.Enabled = true;
}
}
Is there another way to do this?
I tried using css but that didn't work.
<style>
.disabledStyle
{
color: black;
}
</style>
myDDl.CssClass = "disabledStyle";
There is no readonly property for the dropdownlist control. But you can move the focus to another control when it receives the focus and that will prevent it from being changed and leave the text black.
You need to apply the style to each individual ListItem, and not to the DropDownList itself
I have just put in a dropdownlist and put it to enabled false in the controller, then I found out that it has a class called "aspNetDisabled", I have tried to use CSS to change color on it, it works perfectly.
<style>
.aspNetDisabled
{
color: #FFF;
background-color: #000;
}
</style>
In the code, if you put the dropdownlist, "ddl.enabled = false", it will be like this:
<select name="DropDownList1" id="DropDownList1" disabled="disabled" class="aspNetDisabled"></select>
If the dropdownlists are surrounded by a div with a class, use the class to define the disabled ones:
<style>
.MyCssClass[disabled]
{
color: #FFF;
background-color: #000;
}
</style>
Or try
:disabled,[disabled]
{
-ms-opacity: 0.5;
opacity:0.5;
}
</style>
As said in here:
http://forums.asp.net/t/2028164.aspx?IE+11+disabled+buttons+links+not+shown+as+greyed+out
The simplest way to do that:
<style>
[disabled] { /* Text and background colour, medium red on light yellow */
color:#933;
background-color:#ffc;
}
</style>
I am trying to simulate a click on a image in IE through C# using SHDocVw but have a problem. My program does not seem to find the img in the code.. Here is what I got:
SHDocVw.ShellWindows AllBrowsers = new SHDocVw.ShellWindows();
foreach (SHDocVw.InternetExplorer ieInst in AllBrowsers)
{
mshtml.IHTMLDocument2 htmlDoc = ieInst.Document as mshtml.IHTMLDocument2;
string html = htmlDoc.body.outerHTML;
foreach (mshtml.HTMLImg imgElement in htmlDoc.images)
{
if (imgElement.nameProp.ToString().Equals("icon_go.GIF"))
{
imgElement.click();
}
}
}
Here is a part of the html code im working on:
<TD align=center><INPUT title="View Detail Statistics" style="BORDER-LEFT-WIDTH: 0px; HEIGHT: 14px; BORDER-RIGHT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-TOP-WIDTH: 0px; WIDTH: 14px" src="../App_Themes/Company/Images/icon_go.GIF" type=image name=process1></TD></TR>
A problem is that the picture IS a button on the website but I dont know how to press it through the C# code.
Is there maybe another way to select the button? Like through the name "process1" instead of going for the image name?
As pointed out in your comment you are looping IMG but you should be looping INPUT:
foreach (IHTMLElement element in htmlDoc.all)
{
var input = element as IHTMLInputImage;
if (input != null && Path.GetFileName(input.src).Equals("icon_go.GIF", StringComparison.OrdinalIgnoreCase))
{
((IHTMLElement)input).click();
}
}
I am trying to highlight (around the border) element that is found in selenium webdriver using C#. I have search the net all i found was java codes, but need it in C#.
or is there any other way to do it.
thanks
There is no native way to do this, but because Selenium allows you use to execute Javascript, you can accomplish it just with a little more work:
Therefore the question becomes "how do I change an elements borders in Javascript?"
If you use jQuery it's a little bit easier, you could find the element and then set some border properties. jQuery has a neat little css property that allows you to pass in a JSON dictionary of values, it will handle setting them all for you, an example would be like:
jQuery('div.tagged > a:first').css({ "border-width" : "2px", "border-style" : "solid", "border-color" : "red" });
That would find an element, and set it's border to be solid at 2px wide with a border colour of red.
However, if you already have an IWebElement instance of the element (likely) you can take the 'finding' responsibility out of jQuery/Javascript and make it simpler again.
This would be executed something like:
var jsDriver = (IJavaScriptExecutor)driver;
var element = // some element you find;
string highlightJavascript = #"$(arguments[0]).css({ ""border-width"" : ""2px"", ""border-style"" : ""solid"", ""border-color"" : ""red"" });";
jsDriver.ExecuteScript(highlightJavascript, new object[] { element });
If you just want basic Javascript, then you could make use of the .cssText property, which allows you to give a full string of CSS styles instead of adding them individually (although I don't know how supported it is cross browser):
var jsDriver = (IJavaScriptExecutor)driver;
var element = // some element you find;
string highlightJavascript = #"arguments[0].style.cssText = ""border-width: 2px; border-style: solid; border-color: red"";";
jsDriver.ExecuteScript(highlightJavascript, new object[] { element });
(Although there are more ways, I've just gone for the most verbose to make it clearer)
C# Extension Method: Highlights and Clears in 3 seconds.
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Remote;
using System.Reactive.Linq;
public static class SeleniumUtil
{
public static void Highlight(this IWebElement context)
{
var rc = (RemoteWebElement)context;
var driver = (IJavaScriptExecutor)rc.WrappedDriver;
var script = #"arguments[0].style.cssText = ""border-width: 2px; border-style: solid; border-color: red""; ";
driver.ExecuteScript(script, rc);
Observable.Timer(new TimeSpan(0, 0, 3)).Subscribe(p =>
{
var clear = #"arguments[0].style.cssText = ""border-width: 0px; border-style: solid; border-color: red""; ";
driver.ExecuteScript(clear, rc);
});
}
}
Thanks Arran i just modified your answer..
var jsDriver = (IJavaScriptExecutor)driver;
var element = //element to be found
string highlightJavascript = #"arguments[0].style.cssText = ""border-width: 2px; border-style: solid; border-color: red"";";
jsDriver.ExecuteScript(highlightJavascript, new object[] { element });
it works perfectly...
thanks once again.
Write below JavaScript Executor code in your Class file
public void elementHighlight(WebElement element) {
for (int i = 0; i < 2; i++) {
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript(
"arguments[0].setAttribute('style', arguments[1]);",
element, "color: red; border: 5px solid red;");
js.executeScript(`enter code here`
"arguments[0].setAttribute('style', arguments[1]);",
element, "");
}
Call the above method from Selenium test case to highlight a web page element. Check out below code which shows how it is done. elementHighlight method is called with searchBox as an argument.
#Test
public void GoogleSearch() throws Exception, SQLException {
driver.findElement(By.xpath("//center/div[2]")).click();
WebElement searchBox = driver.findElement(By.xpath("//div[3]/div/input"));
elementHighlight(searchBox);
driver.findElement(By.xpath("//div[3]/div/input")).clear();
driver.findElement(By.xpath("//div[3]/div/input")).sendKeys("Test");
driver.findElement(By.xpath("//button")).click();
}
On executing the above test, Selenium test will highlight the search box on Google home page. You can reuse elementHighlight method for highlighting any elements on web page.