I am trying to retrieve width of my browser in pixels but for some reason I am getting back 640, my resolution is at 1240.
Code I am using is Request.Browser.ScreenPixelsWidth
Does anyone knows why it returns 640 always or if there is another way for me to get the width of the browser upon page load?
You need to populate a hidden field with Javascript (see this question for how to do that), and then send that field back to the server so that it's avaialble within ASP.NET.
ASP.NET is incapable of reading detailed browser information like that directly (you're talking about sending some very specific information from the client's browser to the ASP.NET server where your application is hosted, and there are a lot of problems involved with doing something like that).
See this similar, but less detailed, question:
Asp.Net Get Screen Width
try this
int x = (Request.Browser.ScreenPixelsWidth)*2-100;
you can set width according to your requirement
Related
I am developing responsive web application in the asp.net mvc.
I want to set some product boxes based on the Current browser/screen resolution, but i am getting issue in getting the correct width of browser resolution.
If I write Request.Browser.ScreenPixelsWidth it gives me all time 640*480.
But its wrong. And if I write the var screen = System.Windows.Forms.Screen.PrimaryScreen.Bounds;
var width = screen.Width;
Its giving me correct windows resolution which i have set from my window property. Its giving me 1600*900 which is correct value. But issue here is if i manually make my browser screen small and run again that code at that it also gives me 1600*900, but it should give me the size of what i have done manually small.
Any idea?
Handling browser size on the server, you won't know if the user resizes the browser between requests. The correct way to handle browser size is on the client with CSS media queries. Media queries allow you to dynamically set different styles for different browser sizes, i.e. a more responsive layout. Here's a decent intro:
http://kyleschaeffer.com/development/responsive-layouts-using-css-media-queries/
I want to submit my app on windows store but due to one error I can't.
Error:
Content compliance: failed
The app failed to resume properly from snapped view.
How to sort out this error? I have check here but not able to get proper solution.
It doesn't look like your app fluidly adapts to the snapped view. Perhaps that is why it failed.
If you keep the default minimum width of 500 pixels, you do not have
to make any special considerations for your app at narrow widths. You
simply design your app so that it adapts fluidly when the user resizes
the app
One should keep provisions for snap view in UI.
Its in UX Guideline of store app.
if its not supported then appropriate view should generated for the same
This Link will helpfull to you
I have a web application on VS2005 using C#.
Whenever my webpage does not open up in full screen, the icons and labels will automatically adjust to fit the width of the windows, making the buttons and icons disoriented.
Is there any way to disable this or enable the format to be fixed regardless if the windows is full screen or not?
This would be hard to do. You could use a function in javascript to chceck if browser is in full screen. Then you woud have to do this in intervals to make sure that this is or is not true.
if (screen.width == window.innerWidth && screen.height == window.innerHeight) {
// web browser full screen
}
Based on that you could make another screen CSS template that you could apply based on that condition. Then you could make your site apply another layout.
Another approach I would reccoment is to make your CSS layout in a way that you would be satisfied with it with any browser size.
You can use CSS to set width (which will be fixed) or min-width (layout will not shrink to less). min-width is not supported on older versions of IE.
In both cases if the browser window is smaller (or the available space – if something like history is opened down the side) than this then horizontal scrolling will be alloed.
However consider that many users have very wide screens these days, far too wide for comfortable reading if a browser is maximised.
is it possible to take a screenshot of what a textbox holds when the user presses the sumbit button for example?
EDIT: this is an aspx webpage
In short, no it is not possible to do this in a consistent, cross browser fashion (that I am aware of). If your textbox was implemented inside of a flash movie, it would be possible to take a 'screenshot' of what the flash movie was displaying when a button was pressed (discussion on this subject available here). But otherwise, you are going to have to do this processing on the server.
You could simulate this process by having the server render a copy of the page itself (feeding it the data the user entered) and then doing what you wanted with it from there. There are free and paid for solutions to assist you in taking a screenshot of a website (browse options available here).
On the client side I think you're stuck with the limitations of javascript, which might not be possible. Here is another question that is very similar to yours:
Take a screenshot of a webpage with JavaScript?
In the general sense, no, you can't. However if you have a constrained environment (e.g. kiosk, intranet), you can create a browser plug-in which can essentially do anything, including snapping a screenshot and sending it to the server.
If you have lots of control over the environment, you can create your own web browser which can take screenshots. In fact, I've done this with C#. I just wrote an app that hosts a browser control and sends screenshots to the server on certain key presses or at a user-defined interval.
How to use C# to capture a image of a specific url?
I want to use C# to automatically capture a image of a webpage based on a specific url.
For example, I have a page contains a txtUrl.Text = "http://www.some.com/index.aspx" , then I click a button, how can I capture a image of that Url?
I assume you want to do this from ASP.NET (as opposed to from a WinForms application).
In your web project, add a reference to System.Windows.Forms (yes, this is a bad thing to do). In your code-behind, you can then create an object of type System.Windows.Forms.WebBrowser:
WebBrowser browser = new WebBrowser();
// this will load up a URL into the web browser:
browser.Navigate(#"http://www.stackoverflow.com");
Next, just use the BitBlt API function (sorry, I don't have a link handy) to copy the WebBrowser control's graphical display to a Bitmap (which you can then display or save or whatever). With this function, the WebBrowser's Handle property is one of the parameters to pass.
Update: here's a link to some code that does exactly what you need: http://www.developerfusion.com/code/4712/generate-an-image-of-a-web-page/
If you mean a visual of the webpage, one approach is to integrate IE to your application and programmatically taking a screenshot. This (for the integrated web browser) and this (for taking screenshots with C#) may be of use. This is of course IE dependent.
Another option is using the shotserver and shotfactory projects used for browsershots.org. They can be found here, though I'm not sure if there's a .NET API for it.
I don't think that is really possible only using C#. That is because C#, or the .NET framework for that matter, don't offer any kind of HTML markup rendering capabilities. The closest you can get - in my opinion - would be to use a WebBrowser control and then try to somehow capture it's graphical output (which would be the rendered page).
The other way to do it would be to look for a .NET component that might do what you want.. Although I don't know of any that do.