Silverlight page navigation - asp.net

I'm using silverlight content within a aspx page.i have created silverlight page is in a separate silverlight project and i have added that project to my normal asp.net application ClientBin.i need to redirect to a aspx page on my asp.net project from a silverlight page button click.how can i achive this?

I think you have one of two options. In your view model for that silverlight control, during the initialization, Bind the navigate URI for a hyperlink button to the desired URI you want to navigate to. Option 2 (a lot smoother): On the click method, Invoke a javascript method on the page that hosts the silverlight object. That method would then do some sort of smooth jquery transition or just a simple navigation for you.
Option 1: <HyperlinkButton NavigateUri="{Binding DesiredURL}" TargetName="_blank" />
For option 2, remember to include:
using System.Windows.Browser;
Option 2:
public void OnFancyNavigate(string _destination)
{
//call the browser method/jquery method (I used constants to centralize the names of the respective browser methods
try
{
HtmlWindow window = HtmlPage.Window;
window.Invoke(Constants.TBrowserMethods.BM_FANCYNAVIGATE, new object[] { _destination});
}
catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); }
}
Lastly, define the javascript method in the aspx/html/.js file that hosts the xap content:
function fancyNavigate(_destination) {
//some fancy jquery or just the traditional document.location change here
}
C# will locate the javascript method when invoked from your code, and you should be good to go

Related

Page_ClientValidate in undefined

I have an asp.net user control which is plugged into both asp.net and MVC pages
When the control is on an asp.net page the client validation in it works fine but when the control is on an MVC page the following call in the js validation fails;
Page_ClientValidate('ValidationGroup');
with the error in Chrome: Object [object global] has no method 'Page_ClientValidate'
How can I get my client side validation to work on my mvc pages when the hyperlink button is clicked?
I need whatever the solution is to work across both MVC and ASP.Net as our site is a combination of the two
Try something like this,
$('#Form').submit(function () {
if (typeof (Page_ClientValidate) == 'function') {
Page_ClientValidate();
if (Page_IsValid == true) {
alert('the form is valid');
}
} else {
if ($(this).valid()) {
alert('the form is valid');
}
}
});
What Kind of validations are you trying to do?
first option:
MVC gives you great tool for validations:
Have you heard about "Data Annotations" tool?
as you configure your model fields you can use the common validation annotation called "required" for example:
Model:
[Required ("ID Field is Required")]
public int ID {get; set;}
View:
#html.texboxfor(m=>m.ID)
#validatefor((m=>m.ID)
and on the view you'll see a red message next the the input field you're trying to validate.
you can change the default messages design and location using CSS.
There is a good Tutorial for that matter at:
http://www.asp.net/mvc/tutorials/mvc-music-store/mvc-music-store-part-6
there is more data annotation validations, it depends on what kind of validations are you trying to do..
Second option:
you can use validate.js for input validations - it gives you the ability to validate almost any kinds of inputs - from numbers and strings to tables, and you can custom you own validation rules...
Default Option:
Build your Own Validation Method using native js for example:
if( $(.myClass).length<0 )
{
alert( "Please Insert Value" );
return false;
}
EDIT:
you can create :
View:
#using("actionMethod","controller")
{
<!--Content contains "names" of tags-->
<input type="submit"/>
}
OR
Controller:
When post back occurred , check the names and return to the same View, if the names are not satisfy.
end EDIT
If you have more questions, please ask.
Hope I Helped, Good luck.
Is there anyway to use an MVC Razor validation method on an ascx web forms user control that is being embedded in an MVC View using RenderPartial?
The problem I now have is that my ascx user control has a custom validation control on it (just the standard web forms custom validator) and when this control is used on an MVC View (by using Render Partial) the view errors with the following error;
Control 'ctl00_ProductListView_ctrl5_ctl00_ctl00_valValueMultiple' of type 'CustomValidator' must be placed inside a form tag with runat=server.
This is because the MVC view doesn't have a form on it obviously but I can't simply add one.
I cant'simply change this from an ascx web forms user control because it is dynamically added to both MVC and Web Forms pages (we have a mixed site of MVC and Web Forms - this is beyond my control) throughout our website.

Windows Phone - Add CSS to WebBrowser displaying third-party webpage

I have an app that displays pages from a website in a WebBrowser control. I want to add a "position:fixed" to the <header>, either through an inline style or an external stylesheet saved in my app's resources. Is this possible?
It is possible, although I'm not sure if for online 3rd party pages as well - from your code you can invoke any JavaScript method using this method:
webBrowser.IsScriptEnabled = true; // make sure this property is set on your WebBrowser
webBrowser.InvokeScript(methodName, listOfParameters);
you can either have some target JavaScript method in web page code to be invoked, or you can directly invoke any code using the JavaScript "eval" method like this:
webBrowser.InvokeScript("eval", new[] { "document.body.style.zoom=\"80%\"" }
That's the basic idea, how to change your page programatically from C#, I won't go here into details here how to change CSS values using JavaScript.

Custom control does not exist exception in SharePoint

I'm trying to add a custom web UserControl to my SharePoint application. I have added my UserControl to a SharePoint WebPart and now i'm trying to load that WebPart in my page.
But when i add the WebPart i get the following exception:
The file /usercontrols/Test3Report.ascx does not exist.
But i'm 100% sure that both the file and folder exists. The path to the usercontrol also seems fine to me. This is how i try to load my control:
protected string UserControlPath = #"~/usercontrols/";
protected string UserControlName = #"Test3Report.ascx";
private Test3Report mycontrol;
protected override void CreateChildControls()
{
try
{
mycontrol = (Test3Report)this.Page.LoadControl(UserControlPath + UserControlName);
Controls.Add(mycontrol);
}
catch (Exception CreateChildControls_Exception)
{
exceptions += "CreateChildControls_Exception: " + CreateChildControls_Exception.Message;
}
finally
{
base.CreateChildControls();
}
}
This seems right to me. I have no idea why it is complaining that i cannot find the Test3Report.ascx.
I've read something about the TrustLevel not set to full or something. Could that be it? Or any other ideas?
Try adding your new custom control by right-clicking on your solution in solution explorer in VS2010 -> add -> new item , after choosing sharepoint2010 from the list on the right, choose "User control".
This way your control will be automatically created and later deployed in the mapped "~/_ControlTemplates/PROJECTNAME/UserControlNAME.ascx" folder which can be referenced to later.
Also make sure that the user control is included in the package by opening the ".package" file in "Package" folder under solution explorer and checking that the user control is listed under "Items in Package".
Tip: If possible for your use-case, instead of adding the custom control programmatically in CreateChildControls() you can put your destination page in design mode and then add your custom control by dragging and dropping the .ascx file from the solution explorer into you page.

Is it possible to render a web control dynamically?

We have a web control that we want to render into a div on the already loaded page. This needs to happen when the user clicks on a hyperlink in the menu.
The web control has some javascript files that are added to it dynamically in the C# code.
We also arent using aspx files, and want to load the web control onto a normal html page.
Please let me know what would be the best way to do this, or direct me to an article as I'm struggling to find anything useful on the web. any help is appreciated.
You can render your control dynamically in a string, send the string back and place it inside your div. Using ajax you call the code behind to render the control and return you the results.
// load the control
var oCConrol = Page.LoadControl("CustomControl.ascx");
// here you need to run some initialization of your control
// because the page_load is not loading now.
// a string writer to write on it
using(TextWriter stringWriter = new StringWriter())
{
// a html writer
using(HtmlTextWriter renderOnMe = new HtmlTextWriter(stringWriter))
{
// now render the control inside the htm writer
oCConrol.RenderControl(renderOnMe);
// here is your control rendered output.
strBuild = stringWriter.ToString();
}
}
Alternative you can get the same results by just make an extra empty aspx page with only your control inside and call it using Ajax. The result will be again the control
The javascript how ever is dificult and can not go with the control. You can not send text back and then make it run as javascript inside the control, this must be done separated.
I have done something similar by creating a separate, standalone .aspx page and Jquery ajax. Call to the .aspx page using Jquery ajax and return all the rendered HTML from that page via the ajax response.
As far as I know, there is not any way to render a web control outside the context of a .aspx page.

ASP.NET MVC3.0 opeing partial view as popup using J Script

I am new to the ASP.NET MVC 3.0, trying to popup partial view using Jscript/AJAX. Any help is appreciated.
Thanks,
Srini
You can launch a popup window with either javascript or jquery. The popup then points to controller/view so that view is displayed in the popup. If you google opening a popup you'll find lots of resource. Its a client side action so really does not have much to do with mvc. You'll just show your view inthe popup.
You can see this article on how to attach code to launch a popup. This is for webforms but the javascript is still applicable for mvc
Also this SO post
Let's say you create a controller action that returns your partial view, something like this:
public ActionResul get_partial_view()
{
....some logic
return PartialView("partial_view_name");
}
Then in your view where you would like the popup to appear you could use some jquery to load the dom element that will contain the content of the popup window like so:
$.get('/controller_name/get_partial_view', function(html) {
$('#popup-content').html = html;
});

Resources