Hi I have a Windows form the import data to SQL, also I have an aspx page which is used for previewing data which i need to load to to the windows form using WebBrowser Control, my problem is that How do I pass a collection (List) to the aspx page for it to be able to bind to a gridview?
You can't - they are separate things.
The WebBrowser control simply renders an IE window on your form, loading the requested page and rendering it as usual.
If you want to pass data to the webpage from the web application, you will need to get the data to whichever data source (ie: common database etc) the web app reads from then refresh the web page which will read the new data.
Look at ASP.NET application hosting.
There are a couple of examples already written, so you do not have to re-invent all the glue.
Here is the code I used for IronScheme's 'document browser'.
Here you can see how I setup the server part in a simple console app, but creating a windows forms one is not hard.
As for passing data, you can simply just dump it in the ASP.NET application state, and then read that back from within your ASPX page.
Related
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 am working on a project in which one functionality is that this page obtains data from other page (not web service) and then displays it on a grid and use hightcharts for charting.
The problem is that this data I want to read is in anotherpage.
I know that I can read html from other pages... but to get this information on the page, I need to fill 2 input text for a filter and press a submit button.. then it displays a table and this is the table where I need to extract the information.
Is there a way to do this automatically on c#?
There are plenty of ways to do this; the most common revolve around AJAX. You can initiate a callback from the client via Javascript to a method on the server, which can update controls in an UpdatePanel, for example.
You can also make client side calls to server side Page Methods. Effectively, this is a static method on your webform that you can call from the client via javascript/jquery and AJAX.
EDIT.
It turns out that you want to scrape another site. The easiest way for you to do this is have a server side page method on your website that does this - it requests the page from the client site, extracts the info you want, and then returns that to your client. Your client can of course call this as a page method.
See https://web.archive.org/web/20210513000146/http://www.4guysfromrolla.com/webtech/070601-1.shtml for a tutorial, and I do suggest using the HTML Agility Pack as that article mentions.
Further EDIT
You want to further manipulate the page on the remote site; if you can't or don't want to speak to the developers of that site to work out a way of doing it programmatically, then you'll have to cheat. Get Firebug and Tamper Data. Use Firebug and Tamper Data to see how clicking the button on the remote site makes a request and posts it to the server - you want to emulate doing the same. If you know what data is being posted then you can, from your server, make exactly the same post.
You often have this kind of problem when trying to scrape AJAX websites.
I am developing a windows phone application in visual studio (Silverlight in C#) and I added a browser control to the application that i develop to show some random website.
Now i need to run a javascript along with that page in the browser control. How do i add the script to that. is there anyway to append the script directly when the html loads?
The script can be loaded from remote server or from the application itself. Its just to modify the pages a bit and display.
Instead of using the NavigateTo(URI) method of the WebBrowserControl directly with the URL, you can get the source of the HTML page as a string, modify it by injecting your javascript and use the NavigateToString(string html) method to display the content.
I have an application in C# Windows Forms and I want to add a feature that is available only by jQuery. I implemented what I need in a new aspx file (new project). The question is, how do I connect it with my WinForms app? I need to send some data from my app to the website. These data are contained in a data structure of type Dictionary and I need them in the same format/structure in my website. Can I embed the website inside my form or do I have to call the aspx project from within my app?
Thanks.
You'll have to post the data in some way to the website. Use a WebRequest with the data in the post to send the List data to the website as eg. XML.
Maybe it would be simpler to upload the results to a database and simply open the browser with some ID to point to the database results. (process.Run("iexplore http//website.aspx?id=124)
You can do it if you absolutely need it, see Using ASP.NET Runtime in Desktop Applications, But you are basically trying to attach bicycle pedals to a motor vehicle.
It can be accomplished with a panel with AutoScroll = true
I'm developing a web site, and i'm using infragistics for web, but I want to use in some pages silverlight controls (Infragistics too). Is there a way to access a silverlight control's properties and methods from an aspx page?
Thanks in advance for the help.
The silverlight control is running on the client so the best way to access the silverlight's control data is by exposing via javascript methods.
You can map your properites and functions in your silverlight control to javascript methods and then call them as needed.
If you need access the silverlight data server side, then you should expose what you need via javascript and then call the javascript function before a postback and have it write values to a hidden field so that you can then retrieve them server side by accessing the request's posted values.
To expose your some data via javascript just create function in your silverlight page like:
[ScriptableMember]
public int GetValueFromSilverlight()
{
// lame example
return int.Parse(textBox.Value);
}
You could then call this function client side and write it's values to a hidden field which will cause it to post along with the rest of your data.
I asked a similar question a while back when I was working on a silverlight project.
Another thing you could do (which I don't recommend) is to have your silverlight control write back to the application's session or database via web services and then your server side page calls can read the data from whatever location you have written to.
The main point is your need some type of intermediate to get the data back to server so it is accessible and you want something is flexible (hidden field method was my choice).