Setting Focus to a silverlight 4 application in an MVC 3 view - asp.net-mvc-3

I'm having trouble with this. While it just means people have to click on the object to get it to respond, I think it looks unprofessional as hell.
Here is the view (including my n'th attempt):
#{
ViewBag.Title = "Show";
//Layout = "~/Views/Shared/_Empty.cshtml";
Layout = "";
}
<script src="#Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>
<script src="#Url.Content("~/Scripts/modernizr-1.7.min.js")" type="text/javascript"></script>
<script src="#Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="#Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<script src="#Url.Content("~/Scripts/jquery-ui-1.8.11.min.js")" type="text/javascript"></script>
<script src="#Url.Content("~/Scripts/jquery.alerts.js")" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
$('#HDViewerSL').focus();
});
</script>
<div id="silverlightControlHost" >
<object id='HDViewerSL' data="data:application/x-silverlight," type="application/x-silverlight-2" width="100%" height="100%">
<param name="minRuntimeVersion" value="4.0.60310.0"/>
<param name="autoUpgrade" value="true"/>
<param name="source" value="#ViewBag.HDViewSLXap"/>
<param name="background" value="black"/>
<param name="initParams" value="source=#ViewBag.ImagesUrl,id=#ViewBag.Id"/>
<div style="text-align:center;font-family:Arial;margin-top:50px;">
This page requires Silverlight 4.<br />
<br />
<a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=4.0.60310.0" style="text-decoration: none;">
<img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="Get Microsoft Silverlight" style="border-style: none"/>
</a>
</div>
</object>
<iframe style='visibility:hidden;height:0;width:0;border:0px'></iframe>
</div>
In my Silverlight constructor, I have:
this.GotFocus += new RoutedEventHandler(HDViewer_GotFocus);
This event is never firing.
Anyone know how to get the focus set on the object?
Thanks,
David

You can request the plugin to be focused from within you Silverlight application using HtmlPage.Plugin.Focus(); The Loaded event of the MainPage is normally the right place to do this.

I was getting "Invalid Operation Exception" with that code, but I had it in the constructor. At your suggestion #Avee I put it in the constructor instead of in the load event and there was no change. The problem was that I needed to add:
<param name="enablehtmlaccess" value="true"/>
to the Silverlight object's parameters in the hosting page. (ref: http://weblogs.asp.net/albertpascual/archive/2009/04/13/silverlight-exception-the-dom-scripting-bridge-is-disabled.aspx)
Thanks!
David

Related

Ajax.BeginForm redirect instead of replacing div container [duplicate]

My Search.cshtml has a div named "search-results" that is to be updated. SearchResults is the action name. I have done this many times on MVC2/VS2008 projects, but this is my first using MVC3 and VS2010.
The problem is, instead of my search result being rendered in my div, it clicking submit is redirecting me displaying my partial as a standalone page.
I have read that this may be because Ajax is not enabled. My _Layout.cshtml looks like this:
<!DOCTYPE html>
<html>
<head>
<title>#ViewBag.Title</title>
<script src="#Url.Content("~/Scripts/2011.2.712/jquery-1.5.1.min.js")" type="text/javascript"></script>
<link href="#Url.Content("~/Content/themes/base/jquery.ui.core.css")" rel="stylesheet" type="text/css" />
<link href="#Url.Content("~/Content/themes/base/jquery.ui.datepicker.css")" rel="stylesheet"  type="text/css" />
<link href="#Url.Content("~/Content/themes/base/jquery.ui.theme.css")" rel="stylesheet" type="text/css" />
<link href="#Url.Content("~/Content/main.css")" rel="stylesheet" type="text/css" />
<link href="#Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
<script src="#Url.Content("~/Scripts/2011.2.712/jquery-1.5.1.min.js")" type="text/javascript"></script>
#(Html.Telerik().StyleSheetRegistrar().DefaultGroup(group => group.Add("telerik.common.css").Add("telerik.transparent.css").Combined(true).Compress(true)))
</head>
<body>
<div class="page">
<div id="header">
<div id="title">
<h1>My MVC Application</h1>
</div>
#(Html.Telerik().Menu()
.Name("menu")
.Items(menu => {
menu.Add().Text("Home").Action("Index", "Home");
menu.Add().Text("About").Action("About", "Home");
menu.Add().Text("Employees").Action("List", "Employee");
}))
</div>
<div id="main">
#RenderBody()
<div id="footer">
</div>
</div>
</div>
#(Html.Telerik().ScriptRegistrar().DefaultGroup(group => group.Combined(true).Compress(true)))</body>
</html>
Do I need to add MicrosoftMvcAjax.js or jquery.unobtrusive-ajax.js in? My web.config (root) contians the following:
<appSettings>
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
If I add MicrosoftMvcAjax.js in at the end of the element, I get an error sayning namespace 'Type' is undefined error from the first line of MicrosoftMvcAjax.js:
Type.registerNamespace('Sys.Mvc');Sys.Mvc.$create_AjaxOptions=function(){return {};}
What am I missing here. I am sure my code is fine, as it copied alsmost verbatim from my MVC2 projects.
You forgot to include the jquery.unobtrusive-ajax.js script to your page (adjust the path as necessary):
<script src="#Url.Content("~/Scripts/jquery.unobtrusive-ajax.js")" type="text/javascript"></script>
As far as Microsoft*.js scripts are concerned, they are obsolete in ASP.NET MVC 3 and should no longer be used unless you are porting some legacy application. They have been replaced by jQuery.
Ok, figured out my problem.
I was calling Ajax.BeginForm with the AjaxOption OnSuccess pointint to a js function that updated my place holder. But this is not needed, with unobtrusive. Once I removed the OnSucces from the Ajax options everything started working.
~S

How to filter items in Outlook View Control

I'd like to show content of outlook inbox folder filtered to particular subject using Outlook View Control. I try different parameters to Filter and Restriction parameters (like "Subject"="Test", Subject:"Test" etc), but it don't work. All items are displayed. I'm testing it on Outlook 2010 32 bit.
Thanks for suggestions
Sample Code:
<html>
<head>
<title>Outlook view filter test</title>
</head>
<body topmargin=0 leftmargin=0 scroll=no>
<OBJECT classid=CLSID:0006F063-0000-0000-C000-000000000046 id=tasks height="30%" width="50%">
<param name="Folder" value="Inbox">
<param name="Namespace" value="MAPI">
<param name="Restriction" value="[subject]:'Test'">
<param name="Filter" value="[subject]:'Test'">
<param name="DeferUpdate" value="0">
</OBJECT>
</body>
</html>
You don't want to use Filter, as the documentation says:
represents the Distributed Authoring and Versioning (DAV) Searching and Locating (DASL) statement used to restrict the display to a specified subset of data. Read/write
Instead just use Restriction. With Restriction = means contains, see documentation: https://msdn.microsoft.com/EN-US/library/office/ff865641.aspx
<html>
<head>
<title>Outlook view filter test</title>
</head>
<body topmargin=0 leftmargin=0 scroll=no>
<OBJECT classid=CLSID:0006F063-0000-0000-C000-000000000046 id=tasks height="30%" width="50%">
<param name="Folder" value="Inbox">
<param name="Namespace" value="MAPI">
<param name="Restriction" value="[Subject]='Test'">
<param name="DeferUpdate" value="0">
</OBJECT>
</body>
</html>

Rendering pages in mvc3 from xml

I want some static pages of application to be rendered from XML i.e. i am planning to have a base page and xml containing structure of the page and xslt which will be transforming this xml to html and at runtime i will be rendering this html to my view and displaying this view
Is there any way/ example for doing the same. Please help
Here is the sample xml
<!DOCTYPE html>
<html>
<head>
<title>Create</title>
<script src="/Scripts/jquery-1.5.1.min.js" type="text/javascript" />
<link href="/Content/themes/base/jquery-ui.css" rel="stylesheet" type="text/css" />
<link href="/Content/Site.css" rel="stylesheet" type="text/css" />
<script src="/Scripts/jquery-ui.js" type="text/javascript" />
<script src="/Scripts/jquery.validate.min.js" type="text/javascript" />
<script src="/Scripts/jquery.validate.unobtrusive.min.js" type="text/javascript" />
<script src="/Scripts/jquery.unobtrusive-ajax.js" type="text/javascript" />
</head>
<body>
<div id="menucontainer">
<ul id="menu">
<li>
Rutu
</li>
<li>
Employee
</li>
</ul>
</div>
<h2>Create</h2>
<script src="/Scripts/jquery.validate.min.js" type="text/javascript" />
<script src="/Scripts/jquery.validate.unobtrusive.min.js" type="text/javascript" />
<form action="/Employee/Create" method="post">
<fieldset>
<legend>EmployeeDetailsModel</legend>
<div class="editor-label">
<label for="EmpName">EmpName</label>
</div>
<div class="editor-field">
<input class="text-box single-line" id="EmpName" name="EmpName" type="text" value="" />
<span class="field-validation-valid" data-valmsg-for="EmpName" data-valmsg-replace="true" />
</div>
<div class="editor-label">
<label for="DeptId">DeptId</label>
</div>
<div class="editor-field">
<input class="text-box single-line" data-val="true" data-val-number="The field DeptId must be a number." data-val-required="The DeptId field is required." id="DeptId" name="DeptId" type="text" value="" />
<span class="field-validation-valid" data-valmsg-for="DeptId" data-valmsg- replace="true" />
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
</form>
<div>
Back to List
</div>
There is a good blog post here that describes how to create an HTML Helper to render the XSLT in a view. You just call the helper class from your view passing in the path to the XSLT and the XML. I have modified this helper so that you can also pass the XSLT and XML as strings to achieve the same results.
MvcContrib project provides an XSLT based view engine http://mvccontrib.codeplex.com/releases - I would suggest to check it out.

Ajax.BeginForm doesn't work when deployed to WebServer

I have the following view definition in my asp.net mvc website:
<% Using Ajax.BeginForm("UsrCtlChangePassword", "User", Nothing, New AjaxOptions With {.UpdateTargetId = "resultDiv", .InsertionMode = InsertionMode.Replace, .HttpMethod = "Post"}, New With {.id = "myFormID"})%>
<%: Html.ValidationSummary(True, "Invalid details supplied.")%>
...View field definition in here
...
<% End Using%>
</div>
So basically when the user enters invalid information (old password doesn't match) the whole page isn't refreshed just the targetdiv.
This works perfectly in my dev environment. The problem I have is that I have now deployed it to my web host server (softsys windows 2008 server) and it doesn't work upon the deployed server. It totally ignores the ajax insertion mode logic and just sends back the entire form.
Why would it be working in dev and not on the deployment server? I've checked all the dlls and scripts and everything seems to be there. Following is the dll's in my bin folder:
I've got the following keys set in my web.config (I changed the UnobtrusiveJavaScriptEnabled to true and it didnt make a difference):
<add key="webpages:Version" value="1.0.0.0" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="false" />
And this is the script links in my site.master:
<link href="../../Content/Site.css" rel="stylesheet" type="text/css" />
<link href="<%: Url.Content("~/Content/themes/Redmond/jquery-ui.css")%>" rel="stylesheet" type="text/css" />
<script src="<%: Url.Content("~/Scripts/jquery-1.5.1.min.js") %>" type="text/javascript"></script>
<script src="<%: Url.Content("~/Scripts/modernizr-1.7.min.js") %>" type="text/javascript"></script>
<script src="<%: Url.Content("~/Scripts/jquery-ui-1.8.11.min.js") %>" type="text/javascript"></script>
<script src="<%: Url.Content("~/Scripts/jquery.cookie.js") %>" type="text/javascript"></script>
<script type="text/javascript" src="<%: Url.Content("~/Scripts/MicrosoftAjax.js") %>"></script>
<script type="text/javascript" src="<%: Url.Content("~/Scripts/MicrosoftMvcValidation.js") %>"></script>
<script type="text/javascript" src="<%: Url.Content("~/Scripts/MicrosoftMvcAjax.js") %>"></script>
Any ideas?
Thanks in advance.
I worked it out, it ended up being that I needed to add the following lines to my site.master:
<% Html.EnableClientValidation()%>
<% Html.EnableUnobtrusiveJavaScript(False)%>
For some reason the keys I set in the web.config were being ignored when deployed to the webserver. As soon as I added these lines to the site master everything worked as it should.

jQuery-Mobile not running in Windows Phone 7?

I doing one simple task in jQuery alpha 4. It run in browser but when I run in WP7 emulator, it shows only white screen? can any one suggest me how to run in WP7?
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Alpha 4 test</title>
<!-- alpha 4 for jQuery mobile -->
<link rel="stylesheet" href="script/jquery.mobile-1.0a4.min.css" />
<script type="text/javascript" src="script/jquery-1.5.min.js"></script>
<script type="text/javascript" src="script/jquery.mobile-1.0a4.min.js"></script>
<script type="text/javascript">
function callpage2()
{
$.mobile.changePage("#detailpage","slide",false,false);
}
</script>
</head>
<body id="callweb">
<!-- /Page Starts -->
<div data-role="page" id="searchpage">
<!-- /header Starts-->
<div data-role="header" data-backbtn="false">
<center><font size="2"><h3>Saxo Tech</h3></font></center>
</div>
<!-- /header Ends -->
<!--Content Begins-->
<center>
<div data-role="content" id="content">
First page
Using ID
<button onclick="callpage2()"> Using button (mobile changepage)</button>
<ul data-role="listview" data-inset="true" data-theme="e">
<li><img src="script/images/11.jpg" class="ui-li-thumb" /> <a style="margin-left:1em;">one</a></li>
<li> <img src="script/images/globe.jpg" class="ui-li-thumb" /><a style="margin-left:1em;">two</a></li>
</ul>
</div>
</center>
<!--Content Ends-->
</div>
<!-- Page End-->
<!-- Detail Page Starts -->
<div data-role="page" id="detailpage">
<!-- /header Starts-->
<div data-role="header">
<center><font size="2"><h3>Saxo Tech</h3></font></center>
Back
</div>
<!-- /header Ends -->
<!--Content Begins-->
<center>
<div data-role="content" id="content">
second page
</div>
</center>
<!--Content Ends-->
</div>
<!--Detail Page End-->
</body>
</html>
The debug capabilities on the mobile browser are not very advanced.
The best way to debug this is to try using the desktop browser instead. Does this example run on IE7 (or IE9 running in compatible mode)? Get it working there first, then move it across to the mobile UI.
I would suggest to used the CDN instead your local files for invoking jQuery and jQMobile just to start.
change this
<link rel="stylesheet" href="script/jquery.mobile-1.0a4.min.css" />
<script type="text/javascript" src="script/jquery-1.5.min.js"></script>
<script type="text/javascript" src="script/jquery.mobile-1.0a4.min.js"></script>
into this
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0a4/jquery.mobile-1.0a4.min.css" />
<script src="http://code.jquery.com/jquery-1.5.2.min.js"></script>
<script src="http://code.jquery.com/mobile/1.0a4/jquery.mobile-1.0a4.min.js"></script>
I have run into this same issue before.
For me it was an issue with my html syntax and I think is could be a similar issue here (It seems JQM under WP7 is very picky about its HTML)
I'd start with the centre tags around the content divs, either get rid of them or move them inside. Maybe even the font tags and use CSS classes.

Resources