I am trying to make an application that will fill in the info i type into the actual web page so I can register at websites very very easy whenever I need them. However I'm not sure how I would go about this. I know I would either have to use a WebBrowser or an Html request, but I am not sure what the basic syntax for it is. I could really use the help!
EDIT: I am trying to use Document.GetElementByID in order to do this. I don't want to use plugins to do this. I want to go a program.
Look into Browser Helper Objects and how to implement them in .NET. BHO-s can interact with the page loaded into an IE browser.
Related
I'm having a web application project which is running .NET 4.0. I've plenty of .aspx page and now I would like to add in a block of script code to all the .aspx page header, for example Google Analytics.
I know there is a solution to do is add in every single page, but I would like to know is there any other's way to do this instead modify every single .aspx page?
*My header is not runat server
I got an idea to do but not sure it's work or not.
Get the page class in Global.asax
Get the output stream from the page class.
Insert the Google Analytics code in the HTML header.
I couldn't get the Page.Response in the Global.asax as I tried in the Application_PostRequestHandlerExecute & also Application_EndRequest. Does anyone know is this work and how it's work?
Thanks.
Use master pages. This is the ASP.NET way of putting the same content on multiple pages without repeating yourself.
All of our aspx pages code-behind classes inherit from the same base class, which allows us to inject standard client side elements (controls, script, etc) into every page using a single point of control.
Our design was implemented before the advent of master pages, but while it could possibly be converted to a master-page design, we have found this implementation to be extremely flexible and responsive to changing needs.
For example, we have two completely separate application designs (different skin, some different behavior) that is based off of the same code base and page sets. We were able to dynamically swap out banners and other UI and script elements by simple modifications to the base class in order to support this without having to duplicate every page.
Unfortunately, if you want the script to be in the head element, you will need to ensure that they are all marked as runat=server.
Our base class itself inherits from Page, so it can intercept all of the page's events and act on them either instead of or in addition to the inheriting classes (we actually have internal overrideable methods that inheritors should use instead of the page events in order to ensure order of execution).
This is our (VB) code for adding script to the header (in the Page's LoadComplete method):
' sbscript is a stringbuilder that contains all of the javascript we want to place in the header
Me.Page.Header.Controls.Add(New LiteralControl(sbScript.ToString))
If it is not possible to change the heads to runat server, you could look into ClientScriptManager method RegisterClientScriptBlock which places the script at the top of the page.
You can create a basic page with the header with the custom code such as Google analytics and have the other pages inherit from that. It will facilitate two things:
1) In case you ever want to change the custom code you will only have to do it in one place
2) No repetitive code hence more maintainable
I am trying to do the same thing on a legacy app that we're trying to decommission. I need to display a popup on all the old pages to nag users to update their bookmarks to use the new sites, without forcing them to stop using the legacy site (yet). It is not worth the time to convert the site to run on a master page when I can just plop in a popup script, since this whole thing is getting retired soon. The main new site uses a master page, which obviously simplifies things there.
I have this line in a file that has some various constants in it.
Public Shared ReadOnly RetirementNagScript As String = "<Script Language='javascript'> alert('[app name] is being retired and will be shut down [in the near future]. Please update your bookmarks and references to the following URL: [some URL]'); </script>"
Then I am inserting it in Global.asax, in Application_PostAcquireRequestState:
Response.Write(Globals.RetirementNagScript)
Hopefully this is useful to you; I still need to be able to present a clickable URL to the user that way, on each page of the legacy site, and JS alert doesn't do that for me.
I'm building SPA application using Backbone.js and as its back-end I want to use ASP.NET Web API. I need only one page and this fact brings me a lot of confusion.
ApiController returns json response and as far as I understand there's no need in asp.net-specific views at all. Am I right?
Can I use plain html for my main page? Or should I use *.cshtml and put a call to RenderBody instead?
If choose the first option then how will I handle validation?
Thanks!
Well the trick is that if you want search engines to be able to index your page, or people to be able to share to Facebook with a custom icon/description, etc you'll need to serve back static HTML -- none of those bots are able to run your javascript to render the page as the browser does.
If you're uninterested in this, then yes, you can completely avoid RenderBody.
I have a new design requirement that uses the facebook fan box unorthodoxically. Instead of 'hacking' the fan box, I'd rather scrape the fan box iframe (hidden) and retrieve the contents of the grid-item class in the .fan_box class (i.e. .fan_box .connections_grid .grid_item). I basically need the URLs to the face images and their links.
I'd prefer .NET methodology or JS/Jquery and something to get me started and pointed in the right direction. Please don't just provide a basic method to pull in a webpage to scrape, that's not the point. It's the iframe and accessing the data within it, is the challenge here.
I've not seen anyone try this and have searched thoroughly. I am not a expert so please give me more direction than you would give a brain-dead monkey. Thanks.
Why not just access the page's /feed connection via the API and display it in your own style?
Start here: https://developers.facebook.com/docs/reference/api/page/ (bear in mind you'll need an access token to access the feed)
A sample of the return type is here:
https://developers.facebook.com/tools/explorer/?method=GET&path=19292868552%2Ffeed
I'm trying to build a headless browser in c#. c# has plenty of classes, which are supposed to make this possible, like, for example JScriptCodeProvider.
I am looking to get IE XML DOM classes for the JavaScript code to work with. Can anyone tell me where to find those, and, if possible, to provide me with a workable example for what I'm trying do to?
Use the webbrowser control. That should get you everything you need.
I have a webservice I need to call via a link. The webservice returns a pdf document and takes a document Id as a input parameter.
Under normal circumstances I could have the link call some code in the code behind which in turn calls the webservice.
However the difficult part about it is I can't add code to the code behind. The reason is it is for some CMS users who want to know what links to add to the page which will download the pdfs. I can only add the link to the aspx page. Is this at all possible?
Thanks!
While it is possible to call a web service VIA a link (making it difficult to add parameters, though), it sounds like the thing you want to do is a generic handler (in ASP.Net, it is an ASHX file).
Here is a good example of how to use one.
You can do this see: http://msdn.microsoft.com/en-us/library/45fez2a8(VS.80).aspx
There are however limitations on the type of input parameters that you can use. Int and String work OK, your own objects do not work.