I am using jqueryuihelpers (http://jqueryuihelpers.apphb.com/Docmo/Dialog) for MVC 4. The following code is from the documentation page.
<p>#Html.JQueryUI().Button("Click me!", new { id = "triggerButton" })</p>
#using (Html.JQueryUI().Begin(new Dialog().AutoOpen(false)
.TriggerClick("#triggerButton")))
{
<p>This dialog is opened with a button.</p>
<p>Please click the X at the top right corner to close it.</p>
}
In the above example, the selector of TriggerClick is for just one button and it works fine.
If I have more than 1 buttons, I would like to use the class selector ".button".
#using (Html.JQueryUI().Begin(new Dialog().AutoOpen(false)
.TriggerClick(".button")))
{
<p>This dialog is opened with a button.</p>
<p>Please click the X at the top right corner to close it.</p>
}
In this case, how I can identify which button triggers the click event which in turn opens the dialog box?
There is a workaround demonstrated in the shopping cart example on the same page.
<div id="cart">
#{Html.RenderPartial("ShoppingCart");}
</div>
#using (Html.JQueryUI().Begin(new Dialog().Title("Remove").AutoOpen(false)
.ConfirmAjax(".removeLink", "Yes", "No",
new AjaxSettings() { Method = HttpVerbs.Post, Success = "removeSuccess", Error = "removeError" })))
{
<p>Remove the item from your shopping cart?</p>
}
It used the class selector and post back to the server and update the partial page content.
It is not entirely what I want. But it works as alternative.
Related
I have two menu items Delete and Create under Menu Icon. I am selecting any operation from Menu Icon which opens confirmation dialog with two button Delete and Cancel.
Initially focus stays on menu icon after selecting any menu item from menu. I want to shift the focus on dialog button by default so that on Enter-Key hit , it close the dialog after performing desired operation.
Please check Demo here Stackblitz
I fixed this issue as Spinner was preventing focus to move into dialog button whenever i was trying to click on Delete from Menu.
I added id="deletebutton" in html as below.
<div *ngIf="!loadspinner">
<mat-dialog-content>
<p>Are you sure to delete this?</p>
</mat-dialog-content>
<mat-dialog-actions align="center">
<button id="deletebutton" mat-raised-button color="primary" (click)="deleteDocument()">Delete</button>
<button mat-raised-button mat-dialog-close tabindex="-1" (click)="close()" style="border-color:#3f51b5;">Cancel</button>
</mat-dialog-actions>
</div>
And added timeout in ngOnInit method in .ts file as below.
ngOnInit() {
this.service.validate(this.data).subscribe(value => {
this.loadspinner = false;
if (value != null) {
this.warningMsg = value.statusMessage;
} else {
this.warningMsg = "";
}
//For autoFocus in dialog button as Spinner prevents it to set by deafault
setTimeout(()=>{
document.getElementById('deletebutton').focus();
});
});
}
Aim: Create a button on the index (home) page that load movies with a status of "View All" from data that has been seeded from database. The button, when clicked, does not direct the user to a different web page but enables the user to stay of the same web page. I created an Ajax.ActionLink on the Index View and created a _ViewAll view file which contains a foreach loop to produce a list of movies with status of "View All". The Controller contains a partialviewresult ViewAll () method that produces a list of movies with the status="View All".
Problem: when I click the "View All" button on the index website, no data is displayed/no movies with status=="View All" is loaded onto the same index page when "View All" button clicked.
Attempted Resolution: I have js unobtrusive and jquery scripts included on the _Layout view page. I have also followed many tutorials and can't seem to figure out what this issue is. Thank you for your time.
Here is my ViewAll method from StoreController:
public ActionResult ViewAll ()
{
var movie = storeDB.Movies
.Include("MovieStatus")
.Where(g => g.MovieStatus.Status == "View All");
;
return PartialView("_ViewAll", movie.ToList());
Here is my Index view:
# model IEnumerable<Cinema1.Models.Movie>
<p>
<div id="View All">
#Ajax.ActionLink("Please Click", "ViewAll", "Store",
new AjaxOptions
{
UpdateTargetId = "View All",
InsertionMode = InsertionMode.Replace,
HttpMethod = "GET"
},
new { #class = "btn btn-default" });
</div>
</p>
Here is my _ViewAll view:
#model IEnumerable<Cinema1.Models.Movie>
<ul>
#foreach (var Movies in Model)
{
<li>
#Movies.Title
</li>
<li>#Movies.MovieStatus.Status</li>
}
</ul>
Basically I replaced the div in the content as soon as I click "Delete" on the Setting menu above. Well it does changes from collapsible set into checkbox with footer below containing two buttons. The buttons are delete and cancel but I can't perform anything with those buttons. For example, If Cancel clicked it should pop the alert popup (For the sake of testing). Please help..
<div data-role="content">
Tambah Katagori
<div id="Outcome" data-role="collapsibleset" data-theme="a" data-content-theme="a" data-collapsed-icon="arrow-r" data-expanded-icon="arrow-d"></div>
</div>
$("#Delete").click(function(){
$("#Outcome").replaceWith('<form><fieldset data-role="controlgroup" id="OutcometoDelete">');
db.transaction (function (transaction)
{
var sql = "SELECT * FROM KatagoriPengeluaran";
transaction.executeSql (sql,[],
function (transaction, result)
{
if (result.rows.length)
{
for(var i = 0; i< result.rows.length; i++ ) {
All2 =result.rows.item(i);
element = $(' <input type="checkbox" name="'+All2.Katagori+'" id="'+All2.Katagori+'"><label for="'+All2.Katagori+'">'+All2.Katagori+'</label>').appendTo($('#OutcometoDelete'));
}
All2 =result.rows.item((result.rows.length-1));
$('#'+All2.Katagori).append('</form></fieldset>');
$("#OutcometoDelete").append('<div id="someFooter" data-role="footer" data-position="fixed"><div id ="navbarFooter" data-role="navbar"><ul><li><a data-role="button" href="#popUpDelete">Delete</a></li><li><a data-role="button" href="index.html#Pengeluaran" data-ajax="false" id="cancelDelete" >Cancel</a></li></ul></div></div>');
$("#OutcometoDelete").trigger('create');
$("#someFooter").trigger('pagecreate');
$('#navbarFooter').trigger('pagecreate');
}
else
{
alert ("Retrieval Error");
}
}, error);
});
});
$("#cancelDelete").click(function(){
alert("oi");
});
This is because your way of event binding will not work for future elements. You can't just bind click event and expect it will work in the future, event(s) must be bind to something inside the DOM.
So this code will not work:
$("#cancelDelete").click(function(){
alert("oi");
});
On the other hand this code will work:
$(document).on('click',"#cancelDelete",function(){
alert("oi");
});
Second code will work because event is bind to document and it will propagate as soon as needed element is part of the DOM and appropriate event is trigger on it. This is also called delegated event binding.
I am looping through an object passed to the View (I'm using ASP.NET MVC 3) and creating a Nav Tab using Bootstrap.
At the moment, the actual TABS work and render fine. The tab-content however doesn't get displayed - Or one of them will if I make it's class "active" which basically shows the current tab-content (It doesn't change when I click on a different tab).
What I want to happen: Click on a tab -> It's content appears.
What currently happens: Click on a tab -> Nothing shows unless I change a tab-content's class to active (like i mentioned earlier).
Below is my code:
<div>
<ul class="nav nav-tabs">
#for (int i = 0; i < 1; )
{
foreach (var cat in Model.MyObject)
{
if (i == 0)
{
<li class="active">#cat.Name</li>
i++;
}
else
{
<li>#cat.Name</li>
}
}
}
</ul>
<div class="tab-content" style="overflow: visible;">
#for (int i = 0; i < 1; )
{
foreach (var cat in Model.Model.MyObject)
{
if (i == 0)
{
<div class="tab-pane active" id="##cat.Name">#cat.Name</div>
i++;
}
else
{
<div class="tab-pane" id="##cat.Name">#cat.Name</div>
}
}
}
</div>
I put a Breakpoint over each foreach loop - there IS content being passed so that's not the problem.
How do I modify the code so the content changes when I select a different tab?
EDIT: I have made an IF function that only makes the first one active. As of now, the tabs can switch, BUT, the contents DON'T switch. Only the first content is shown and it won't change even if I click on another tab.
You have the markup, but not the logic for active class. Bootstrap provides that logic through Javascript.
$('#myTab a').click(function (e) {
e.preventDefault();
$(this).tab('show');
})
Source: http://twitter.github.com/bootstrap/javascript.html#tabs
I have done a similar thing in cakePHP. You need to specify one of them as active so that when the user loads the page they see the active tab. Then when they click on a different tab the js kicks in and moves the active class to that tab. You can put an if statement in to have it only add the active class to the first tab (or whichever tab you want active by default).
I have developed a web site on ASp.net 3.5 with VB which have multiple pages the problem is i want to show all pages in one view user click on link button and coprresponding page should open on single page then user click to other link button and another page open in same browser window with same layout.Please suggest me what should i do?
You could use AJAX to achieve this. So for example let's suppose that you have multiple controller actions that return partial views. You could then create links on your page to those actions:
<%= Html.ActionLink("page 1", "Page1", "SomeController", null, new { id = "link1" }) %>
<%= Html.ActionLink("page 2", "Page2", "SomeController", null, new { id = "link2" }) %>
<%= Html.ActionLink("page 3", "Page3", "SomeController", null, new { id = "link3" }) %>
and 3 corresponding placeholders where the pages would be loaded:
<div id="page1" />
<div id="page1" />
<div id="page1" />
you could now AJAXify those links in a separate javascript file. Example with jquery:
$(function() {
$('#link1').click(function() {
$('#page1').load(this.href);
return false;
});
$('#link2').click(function() {
$('#page2').load(this.href);
return false;
});
$('#link3').click(function() {
$('#page3').load(this.href);
return false;
});
});
I would also strongly recommend you going through the tutorials on the ASP.NET MVC site.