ASP.NET WebForms - Issues disabling list item - asp.net

I am running (ASP.NET Web Forms) VB.Net code and in the aspx page, i have something like this:
<ul id="tabsdefault" class="tab-menu">
<li id="accessingIndividuals" runat="server"><a>Accessing Individuals</a></li>
</ul>
and in the code behind file, i have this code:
accessingIndividuals.Disabled = true
However, before upgrading to .NET 4.6, this code worked and now after the upgrade, it does not disable the list item.
I have also manually changed the aspx page item with this:
<ul id="tabsdefault" class="tab-menu">
<li id="accessingIndividuals" runat="server" disabled="disabled"><a>Accessing Individuals</a></li>
</ul>
but that did not work and nor did the following:
<ul id="tabsdefault" class="tab-menu">
<li id="accessingIndividuals" runat="server" disabled="true"><a>Accessing Individuals</a></li>
</ul>
Any idea what has changed in .NET Framework or how can disable this item?
Looking at the page source using Developer Tools, the output is like this:
<ul id="tabsdefault" class="tab-menu">
<li id="accessingIndividuals" enabled="false" disabled="disabled" class="selected"><a>Accessing Individuals</a></li>
</ul>

Looks like all new Browsers ignore the disable attribute on a list item. One possible solution is:
li[disabled]
{
pointer-events: none;
opacity: 0.6;
}

Related

Pagination Wordpress in Custom Plugin ( Javascript )

Hi I hope someone can help with this. I'm building a wordpress plugin. I just have basic knowledge of php and i managed to build the whole plugin except pagination. I have tried so many code using javascript but none is working for me. Here is the image. I want to divide the items with pagination
Thank you in advance!
A good approach will be to think about the pages like tabs. Then the page link will behave like buttons that show/hide based on the page link clicked.
Here's an example using jQuery
// Add an event listener for when the page link is clicked
$('.page-link').on('click', function(){
// Save the page number that was clicked
var pageNum = $(this).data('page-id')
// Hide any open 'pages'
$('.page-content').hide();
// Find and show the selected page
$('[data-page=' + pageNum + ']'').show();
});
For this to work, you'd need a HTML structure a bit like this
<!-- The Page Link -->
<div>
<ul>
<li class="page-link" data-page-id="1">Page 1</li>
<li class="page-link" data-page-id="2">Page 2</li>
<li class="page-link" data-page-id="3">Page 3</li>
</ul>
<!-- The Page Content -->
<div class="page-content" data-page="1" style="display: none;">
Page 1 content
</div>
<div class="page-content" data-page="2" style="display: none;">
Page 2 content
</div>
<div class="page-content" data-page="3" style="display: none;">
Page 3 content
</div>
</div>
Here is a super basic jsfiddle

ASP.NET WebApp How to change nav bar "Login" to "Logged in"

Hey guys so I've been looking online and i just cant figure this out..
I've used the Visual studio base Web app essentially as a skeleton to start my web app and i have this in "Site.Master" which i think is the class holding everything about the Navigation page:
"<li><a runat="server" id= "liLogin" href="~/Account/Login">Log in</a>
</li>"
I want to change this name "Log in" To Logged in as a result of an if statement
But: i don't know how to call it...
thanks!
<li><a runat="server" id= "liLogin" href="~/Account/Login">
#if(User.IsAuthenticated)
{
<text>Logged In</text>
}
else
{
<text>Log In</text>
}
</a>
</li>

Unable to Navigate using LinkText in Selenium C#

I got the following C# code from Selenium IDE:
driver.FindElement(By.LinkText("Sub Link 1")).Click();
But as it wasn't working, I modified the code below to wait. It is still not working.
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
IWebElement element = wait.Until(ExpectedConditions.ElementExists(By.LinkText("Main Link 1")));
if (element != null)
{
var innerElement = wait.Until(ExpectedConditions.ElementExists(By.PartialLinkText(
"Sub Link 1")));
}
What might be the possible issue?
My HTML:
<html>
Show navigation
Hide navigation
<div id="navlogo"><a title="HOME" href="url">
<span style="position:absolute;width:100%;height:100%;top:0;left: 0;">
</span></a></div>
<ul class="clearfix">
<li>MXLMain1
<ul>
<li>ML1
</li>
<li>ML2
</li>
</ul>
</li>
<li>MXLMain2
<ul>
<li>MK2
</li>
</ul>
</li>
<li>Main Link 1
<ul>
<li>Sub Link 1
</li>
<li>Sub Link 2
</li>
</ul>
</li>
..........................
</html>
How about using xpath?
driver.FindElement(By.XPath("//a[.='Sub Link 1")).Click();
It looks like the link that you are trying to use is from a navigation bar. You will need to use Seleniums Actions class to activate the menu dropdown.
Then use Actions class to move to element and click on it.
public void MouseHover(By locator)
{
element = driver.FindElement(locator);
Actions action = new Actions(driver);
action.MoveToElement(element).Perform();
}
To click same steps.
action.MoveToElement(element).Perform();
action.Click().Perform();
Move to initial element
Move to the second element and use click method

change master page <a href link from content page

i have this on my master.page
<ul class="menu">
<li class="first" runat="server" id="Li2">
<a runat="server" id="A1" href="../NewEntry.aspx">Create a New Entry</a>
</li>
</ul>
when i go to content page ("NewEntry.aspx") i want the link name to be changed to "Update Entry"
<ul class="menu">
<li class="first" runat="server" id="Li2">
<a runat="server" id="A1" href="../UpdateEntry.aspx">Update Entry</a>
</li>
</ul>
any feedback?
Make the link an asp:Hyperlink. Then have the master page expose a function or property:
public void SetLink(string href, string text)
{
A1.NavigateURL = href;
A1.Text = text;
}
Call the function from the main page.
You can use a hyperlink control <asp:hyperlink> and set the url as well as the text values.
I would recommend handling this as a HyperLink control as others have mentioned. If for some reason you must handle this as a server-side HTML anchor, you can access it using the following code from your webform code-behind:
HtmlAnchor link = (HtmlAnchor)(this.Master).FindControl("A1");
link.InnerText = "Update Entry";
You can also define a content place holder where you have "Create a New Entry". Leave that as the default inside that place holder, and only in the content page set content for it to Update Entry.

How can I disable the Menu control from styling itself in javascript?

I'm using Visual Studio 2010 and ASP.NET 4.0 to render a Menu control as an HTML list so I can style it using CSS. Here is the code I am using below
<asp:Menu ID="navlist" runat="server" Orientation="Horizontal"
SkipLinkText="" ClientIDMode="Static" DataSourceID="MenuSource"
MaximumDynamicDisplayLevels="0" IncludeStyleBlock="False"
StaticDisplayLevels="2">
</asp:Menu>
This produces the following HTML
<!-- URL shortened -->
<script src="/WebResource.axd?...t=634066906994188146"type="text/javascript"></script>
<div id="navlist">
<ul>
<li>Link 1</li>
<li>Link 2</li>
</ul>
</div>
At first glance this looks like exactly what I wanted. However, if I open up WebResource.axd there is a whole bunch of javascript code related to the menu. Part of this code is applying it's own inline styles to the list. Using FireBug I can view the HTML markup after the javascript has executed and it looks something like this:
<div id="navlist" style="float: left;">
<ul class="level1 static" tabindex="0" style="position: relative; width: auto; float: left;" role="menubar">
<li role="menuitem" class="static" style="position: relative; float: left;">
Link 1
</li><li role="menuitem" class="static" style="position: relative; float: left;">
Link 2</li>
</ul>
</div>
These inline styles ultimately affect the layout of my page. I have no need for any of the scripts in WebResource.axd. How can I prevent this script from being rendered in the final markup of the page?
You can tell the menu to NOT style itself if you want to just use the IncludeStyleBlock Attribute
By default its turned on "true"
<asp:Menu IncludeStyleBlock="False" />
On your css use the !important
I've created a custom menu (derived from System.Web.UI.WebControls.Menu) and replaced the OnPreRender:
public class MyCustomMenu : System.Web.UI.WebControls.Menu
{
protected override void OnPreRender(EventArgs e)
{
// Don't call base OnPreRender
//base.OnPreRender(e);
}
}
That did the trick.
You can't do much to change the out-of-the-box functionality of the Menu control. However, you could either create your own control or use the CSS Control Adapter Toolkit.
I tried to override the asp:menu with a custom class, but still haven't learned how to simply remove all attributes from the ul, li, and a tags so that I could apply my own css code to a clean list.
Imports Microsoft.VisualBasic
Namespace MCO
Public Class MyCustomMenu
Inherits Menu
Protected Overrides Sub OnPreRender(e As EventArgs)
' don't use this:
' MyBase.OnPreRender(e)
' but leaving this blank produces NO rendered menu
End Sub
End Class
End Namespace
I have also tried the jQuery method:
$("#navlist li,#navlist li a,#navlist ul,#navlist div").removeAttr('style');
But because the .net webresource is the last thing to run, I found that jQuery line didn't work. It should, but doesn't. :(
I managed this by removing inline styles and changing some class names via jQuery. Of course you can re-style every element but it just produces a lot of unnecessary css code.
Use this, if you want to remove those inline styles from li, a, ul and divs:
$("#navlist li,#navlist li a,#navlist ul,#navlist div").removeAttr('style');
Second you can change those class names e.g.:
$("#from-this-element").removeClass(.remove-me).addClass('.new-class');
And I think it's the best way to use this script after the page has loaded.

Resources