You might consider placing your jQuery code inside of a .js file and add a script block with the link to your layout file. Also, add the script block at the end of your body element.
Christopher Reed, MCT, MCPD, MCTS, Microsoft Specialist, MTA
"The oxen are slow, but the earth is patient."
I really think that the issue has something to do wth logged in users vs. unauthenticated users because the exact same JavaScript function is working just fine for unautenticated users.
I did move the JavaScript block to the end of the body element.
Sad to say that this change had zero effect :-(
I really think this issue has something to do with the difference between unanthicated users (works fine) and authicated users (doesn't work) at all. The issue appears to be that the button is not calling the method because I know that method is correct.
Question: Given my code, what would I assign to the click event for the button?
The issue appears to be that the Toggle button is not calling the JavaScript code for authenticated users.
The next logical step would be to add an onclick="something" in the <input ...> button. My problem is that with the current JavaScript code, I have no clue as to what to add and I'm not a JavaScript developer so I don't even know how to change the JavaScript
code to make it callable from an onclick event.
The <div> is populated by Unobtrusive AJAX run by the View within the _Layout.cshtml page.
The button and JavaScript are on the _Layout.cshtml page.
This works fine for unauthentiacted users (i.e. the Public portion of the site) but not for authenticated users.
This is because something is causing the event JavaScript to not fire when the button is pressed.
The next logical step would be to add a onclick="something" to the <input....> code. The problem is that I'm not a JavaScript programmer so I don't know enough about JavaScript to understand how to do this.
That's what I have in the public _Layout.cshtml file but it doen't work right in the private (read authenticated users) _Layout.cshtml.files.
I need a JavaScript function that I can put into a onclick="something" event in the button code for authenticated users because something gets broken after a user logs in.
eric2820
Contributor
2777 Points
1161 Posts
Re: Why is this button event not working?
Jan 03, 2013 03:18 PM|LINK
Okay I changed the button to:
<input type="button" id="button" value="Togle" />
And put a # sign infront of the "button" string in the JavaScript section. Still no joy :-(
http://www.my-msi.net/Admin
blog
If a post helps you, please mark it as Ansered, thank-you.
ramramesh
Member
458 Points
158 Posts
Re: Why is this button event not working?
Jan 03, 2013 04:33 PM|LINK
Hai
Chnage double quats( "") to single quats(')
for
$('#button').click(function() {
$('#onlineUsers').toggle();
Careed
All-Star
18764 Points
3637 Posts
Re: Why is this button event not working?
Jan 03, 2013 04:47 PM|LINK
You might consider placing your jQuery code inside of a .js file and add a script block with the link to your layout file. Also, add the script block at the end of your body element.
"The oxen are slow, but the earth is patient."
eric2820
Contributor
2777 Points
1161 Posts
Re: Why is this button event not working?
Jan 03, 2013 07:10 PM|LINK
Sad to say that this change had zero effect.
I really think that the issue has something to do wth logged in users vs. unauthenticated users because the exact same JavaScript function is working just fine for unautenticated users.
http://www.my-msi.net/Admin
blog
If a post helps you, please mark it as Ansered, thank-you.
eric2820
Contributor
2777 Points
1161 Posts
Re: Why is this button event not working?
Jan 03, 2013 07:15 PM|LINK
I did move the JavaScript block to the end of the body element.
Sad to say that this change had zero effect :-(
I really think this issue has something to do with the difference between unanthicated users (works fine) and authicated users (doesn't work) at all. The issue appears to be that the button is not calling the method because I know that method is correct.
Question: Given my code, what would I assign to the click event for the button?
http://www.my-msi.net/Admin
blog
If a post helps you, please mark it as Ansered, thank-you.
eric2820
Contributor
2777 Points
1161 Posts
Toggle button works for unauthenticated users but not for authenticated users
Jan 03, 2013 08:29 PM|LINK
I have this in my authenticated _Layout.cshtml file:
<html>
<head>
<title>@ViewBag.Title</title>
<link href="@Url.Content( "~/Content/BackOffice.css" )" rel="stylesheet" type="text/css" />
<script src="@Url.Content( "~/Scripts/jquery-1.8.3.js" )" type="text/javascript"></script>
<script src="@Url.Content( "~/Scripts/jquery.unobtrusive-ajax.js" )" type="text/javascript"></script>
<script src="@Url.Content( "~/Scripts/jquery.validate.js" )" type="text/javascript"></script>
<script src="@Url.Content( "~/Scripts/jquery.validate.unobtrusive.js" )" type="text/javascript"></script>
@if ( false )
{
<script src="@Url.Content( "~/Scripts/jQuery-1.8.3-vsdoc.js" )" type="text/javascript"></script>
<script src="@Url.Content( "~/Scripts/jquery.validate.vsdoc.js" )" type="text/javascript"></script>
}
</head>
<body>
<div class="floating-menu">
@{ Html.RenderAction( "Nav", "BackOfficeNav" ); }
</div>
<div class="floating-menu2">
@{ Html.RenderAction( "AdminNav", "AdminNav", new { area = "Admin" } ); }
</div>
<div class="content">
@RenderBody()
</div>
<div class="move-right" id="onlineUsers">
nothing here yet
</div>
<div class="move-right2">
<input id="button" type="button" value="Toggle" />
</div>
<div style="clear: both; height: 1px; margin-top: -1px;">
</div>
<div style="height: 4in; background-color: Transparent">
</div>
<script type="text/javascript">
$(document.ready(function() {
$('#button').click(function() {
$('#onlineUsers').toggle();
alert("toggle button was pressed");
});
});
</script>
</body>
</html>
The issue appears to be that the Toggle button is not calling the JavaScript code for authenticated users.
The next logical step would be to add an onclick="something" in the <input ...> button. My problem is that with the current JavaScript code, I have no clue as to what to add and I'm not a JavaScript developer so I don't even know how to change the JavaScript code to make it callable from an onclick event.
http://www.my-msi.net/Admin
blog
If a post helps you, please mark it as Ansered, thank-you.
Careed
All-Star
18764 Points
3637 Posts
Re: Why is this button event not working?
Jan 03, 2013 09:33 PM|LINK
Have you look at this demo: http://jqueryui.com/toggle/
Also, look at the view source from your browser. Try this in two or three different browsers.
"The oxen are slow, but the earth is patient."
eric2820
Contributor
2777 Points
1161 Posts
Re: Why is this button event not working?
Jan 03, 2013 09:47 PM|LINK
Once again those sites are not using my use case:
The <div> is populated by Unobtrusive AJAX run by the View within the _Layout.cshtml page.
The button and JavaScript are on the _Layout.cshtml page.
This works fine for unauthentiacted users (i.e. the Public portion of the site) but not for authenticated users.
This is because something is causing the event JavaScript to not fire when the button is pressed.
The next logical step would be to add a onclick="something" to the <input....> code. The problem is that I'm not a JavaScript programmer so I don't know enough about JavaScript to understand how to do this.
http://www.my-msi.net/Admin
blog
If a post helps you, please mark it as Ansered, thank-you.
Careed
All-Star
18764 Points
3637 Posts
Re: Toggle button works for unauthenticated users but not for authenticated users
Jan 04, 2013 04:14 AM|LINK
In your script, you should have this: $(document).ready(function () {...});
"The oxen are slow, but the earth is patient."
eric2820
Contributor
2777 Points
1161 Posts
Re: Toggle button works for unauthenticated users but not for authenticated users
Jan 04, 2013 01:36 PM|LINK
That's what I have in the public _Layout.cshtml file but it doen't work right in the private (read authenticated users) _Layout.cshtml.files.
I need a JavaScript function that I can put into a onclick="something" event in the button code for authenticated users because something gets broken after a user logs in.
http://www.my-msi.net/Admin
blog
If a post helps you, please mark it as Ansered, thank-you.