Is it possible to set up a listener in a Silverlight control to listen for events on the hosting aspx web page? I want to have several Silverlight and ASP.NET user controls hosted in a web page. I want to fire an event on one user control, sending an event to the host page (it needs to be notified), and then I want to broadcast an event back to all controls (both Silverlight and ASP.NET) on the form. This this possible to do with Silverlight?
Silverlight is a client side technology. It can interact with the DOM and it can listen to DOM events, but it can't interact with the ASP.NET controls or listen to events from them.
Silverlight is a client-side technology. You are allowed though to call Javascript functions. Having that, you can take advantage of the ASP.NET AJAX to make calls to web methods on the host ASPX page. Even better, you can force a full post-back of the ASPX page from Javascript.
(sorry for the late response. i've just come accross this when looking for something else)
Related
I am trying to understand if this event works properly for web apps? I know this event is very powerful in WPF/Winforms but in regards to a webform or mvc application, i can't see how it would work properly.
My main concern regarding the two scenarios, Native vs Web, is that once the Data(Mvc Model) has been sent to the client. How does a server side event get fired and magically updates the models property value on both sides, if it does at all?
INotifyPropertyChanged doesn't work with ASP.NET MVC.
Because the client in a web app is the browser, you're limited to (mostly) Javascript based solutions. You could use jQuery's 'change' event, and then use AJAX to send data back to the server:
// the email input has changed
$('#email').on('change', function() {
// send the changes to the server
$.post('/url', { email: $('#email').val() });
});
Once you get comfortable with Javascript and how it works in the browser, you can use a framework like AngularJS, or Vue.js, to handle bindings and notifications (and which would be most comparable to how WPF works).
While you can't readily use that in your web pages built using HTML and JavaScript, there are some efforts which include but not limited to Uno Platform and Ooui where the view can be bound to the viewModels and therefore be updated when a property in the VM changes.
As mention in a comment, the other alternative would be to use some sort of socket based communication where changes in the server [viewModels] can be communicated to the client by something like SignalR or WebSync.
I have this requirement for my project. Already there is an existing windows form application,
Which sends email when a button is clicked. There's a lot of code behind the application.
It validates the field serial number which is a text box by connecting to database.
The validation error pops up as another windows form.
It generates a report form after sending an email. There's a configuration button which is accessible only to particular users which opens configuration form which has details of email settings.
Now All this is developed using windows forms. My new requirement is i need to develop
the same in a ASP.NET web page having similar functionality.
I tried using click once deployment, but that's not they needed. they want it as a webpage.
Is there any tool or way i can show the application in ASP.NET web page?
Do i need to start the coding from scratch?
Thanks in advance
As to what Rex said, you are going to have to start from scratch. The coding behind it is different. Validation and functions work differently in asp.net than they do in .net.
You will have to start from scratch for reasons already mentioned. If this is your first ASP.net application here are a few tips for what you want to do:
1- For validation and transfer to the email report to work in a similar way you can use Response.Redirect or Server.Transfer or JavaScript. All of those methods have pros and cons, see Server.Transfer Vs. Response.Redirect for an example of the first two. For javascript you'll need to write a javascript function in the .aspx file or inject javascript in the page with response.write.
2- If you validate with JavaScript you also need to validate server side to make sure someone doesn't try to pass bad values to you. JavaScript can be disabled and users can call your report page and configuration page directly, while with windows forms you control that flow you don't on webpages.
3- You'll probably have to use CSS to style elements in your email configuration form and in your initial form. Positioning, docking, anchoring and so on is completely different in webpage and done with CSS. Have fun learning the CSS boxing model, what absolute positioning is, and what clear and float do ;)
4- The most important thing is that the Web is stateless. You can't use private members to keep information between page reload on the web. When you pass a value between 2 pages the first one doesn't exist anymore so you can't just do Class.somemembervariable as usual. Check out what viewstate, sessionstate and querystring are. When your page reload, without these, everything is loss. Clicking a server-side button cause the page to reload, which you need to handle (it's called postback). This also implies that when you serve the report page you will have to pass some Id for the email and check the user, so when you call the 2nd page you need to pass to it some id so it can work. I spent more time on this one because it's the most important difference between asp.net and windows form.
5- For restricting access to your email settings page you will probably need to use windows authentification if this is an Intranet site or Forms authentification if this is an Internet site. Check Starting ASP.NET Forms Authentication for some basic overview.
6- ASP.Net has a codebehind file where you write the actual code, and an .aspx page where you put the html tags, javascript, styles, and data binding with <%= %> tags.
7- You will probably have to work with IIS as well to make your website work unless you work at a very formal place where specific peoples take care of that. At the very basic you'll have to create an application pool, make it compatible with 32/64 bits and set up authentification in IIS.
I've got to write a .net windows forms application that will open a webpage and then be able to react to the user clicking on certain links on the webpage. The specification I've been given has the links on the webpage just being http links.
Is there a way for my .net application to have a minimal web server on it which will allow it to handle http requests on a given port?
Use an HttpListener.
http://msdn.microsoft.com/en-us/library/system.net.httplistener.aspx
If all you need is to show a webpage, and you don't have any restrictions on the browser used, then the WebBrowser control will do the trick.
Drag it on to your form
Set the Url property to the page you need to display
Attach to the Navigating event
You can now respond to clicks, cancel them, do whatever you like. If it's just responding to client-side clicks you need, you don't need a web server. If you DO need a webserver, WinForms shouldn't have anything to do with it.
webBrowser1.Navigating += new WebBrowserNavigatingEventHandler(webBrowser1_Navigating);
private void webBrowser1_Navigating(object sender,
WebBrowserNavigatingEventArgs e)
{
//Do your thing... maybe set e.Cancel if you don't to navigate
}
Please look at the WebBrowser control and specifically the "ObjectForScripting" property. If you set it to the parent form you can actually handle javascript events from the page loaded in the webbrowser in your c# code!!!
I hope that helps!
There are different ways to do this depending on what functionality you need. If all you need to do is respond to click events, and you don't need "full" http protocol support, you can just open a socket and parse what comes in from the browser.
Alternatively, you can use HttpListener, which takes care of the http protocol parsing for you and is relatively easy to use. For what I think you need, this is probably the preferred approach. Simple, non-compiling example here: https://gist.github.com/1770645.
The "holy grail" is hosting the ASP.NET runtime in your windows forms application. I've done this and it is pretty involved. The runtime has to be hosted in a separate AppDomain, so you end up jumping through a lot of hoops to get everything running and hooked up. It also involves writing an implementation of HttpWorkerRequest that is more full featured that the framework provided SimpleWorkerRequest. Incidentally, this also works for windows services, which gives you a great way to provide service management and monitoring through a browser without having a dependency on IIS.
I have interpreted the question differently to other users, so maybe I am way off but, I read it as he is trying to render web pages from the web and react to a user clicking on a link within the web page.
The only way I can think of doing this is by using some form of renderer ie webkit and hooking into that to intercept the clicks a user makes.
You can use Nancy
Site of project: https://www.codeproject.com/Articles/694907/Embed-a-web-server-in-a-windows-service
I have a .NET desktop application (not web) with a WebBrowser control.
I cannot find any information on how, or if it is even possible, to obtain the HTTP status code when a document is navigated to inside this control. Does anyone know if this is possible or how?
The purpose is to detect codes other than 200 and perform actions accordingly within the application.
A web page is not made up from a single HTTP GET request. The stackoverflow.com front page for example requires 16 requests. Stuff like javascript code, images, page visit counters, coming from different web sites as well. Some of it retrieve from cache instead of downloaded.
WebBrowser (aka Internet Explorer) doesn't support enumerating these individual requests. You'd have to use the HttpWebRequest class, but that of course doesn't make a web page.
I am posting this as a part of my effort in searching the best possible design solution for my requirement.
I am currently working on a complex server control(not user control) in asp.net which is going to be rendered into html elements on the client side.And those html elements needs to do a ajax call backs to the server using js/jquery. Here is the problem. As this is a serverside control and can be added into any application/domain. I dont want to have those callback services hosted separately. Is there any way that I can host those server callback services in the same library? If so, how can I access them from the client side?
I've never tried putting a WebService into a ServerControl, but I know you can create a composite control (a server control that inherits form the CompositeControl class) that has an update panel in it. With that you can do server side processing with asynchronous calls from the client, similar to JQuery calling a WebService.