Get page dimensions using JavaScript in a Content Page - c#

I am trying to use a javascript method in a content page (Referencing master page) to get the current screen dimensions, and write it to a label.
So far, I have had no luck. I tried doing it in both the master, and content page, but the method is simply not working.
Could someone please provide the solution for this?
MasterPage:
<head runat="server">
<title>Lake, Smit People</title>
<!--[if IE ]>
<link rel="stylesheet" type="text/css" href="ProfileStypeSheetIE.css" />
<![endif]-->
<!--[if !IE]>-->
<link href="ProfileStypeSheet.css" rel="stylesheet" type="text/css" />
<!--<![endif]-->
<asp:ContentPlaceHolder id="head" runat="server">
</asp:ContentPlaceHolder>
<style type="text/css">
.style1 { width: 378px; }
</style>
</head>
Default.aspx
<asp:Content ID="Content5" ContentPlaceHolderID="head" Runat="Server">
<script type="text/javascript">
var height = screen.height;
document.getElementById('<%= hiddenLabel.ClientID%>').value = height;
</script>
</asp:Content>

Hello you can try with theses lines, you specific case is the third (clientHeight and clientWidth)
document.body.scrollWidth, document.body.scrollHeight // for the full size of the document
 
document.body.offsetWidth, document.body.offsetHeight //to the displayed size
 
document.body.clientWidth, document.body.clientHeight //customer for size displayed

Have you tried following?
<a href="javascript:alert
('Your resolution is ' + screen.width + 'x' + screen.height);">
Click for your screen resolution </a>

Related

Masterpage in asp.net CSS

My masterpage code:
<head runat="server">
<title>System</title>
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
<style>
.masterfixed { table-layout:fixed; color:rebeccapurple}
.masterfixed td { overflow: hidden;}
</style>
<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css" >
<link href="bootstrap/css/masdesign.css" rel="stylesheet" type="text/css" >
I only want my colour on my masterpage. But why does this apply to all my font in my contentplaceholder. Please help thanks.
You could put your contentplaceholder in a div and give the div the CSS class or the style you want:
<div style="font:bold 12px arial;color:#000000">
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
</div>
If it does not work, try it with a !important at the end of each style:
sytle="color:#000000 !important"
This makes sure that the div uses this style and not a style defined in a CSS class.

redirect to previous page on button click

Below is my design and code where I am trying to redirect to previous page on button click which doesnt work.
<asp:ImageButton ID="btn_back" runat="server" ImageUrl="~/go_back.jpg" OnClientClick="Back()" Height="41px" Width="49px" />
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<link rel='stylesheet' href='style_demo.css' type='text/css' media='all' />
<style type="text/css">
.auto-style5 {
height: 33px;
}
</style>
<script type="text/javascript">
function Back() {
debugger;
history.go(-2);
return false;
}
</script>
</head>
<body>
Use the following:
history.back();
If your desired page is always your last page you navigate from, you can go back.
window.history.back();

extending bootstrap select

I want to use the bootstrap framework along with http://silviomoreto.github.io/bootstrap-select/. it just doesnt work. Below are the codes. Please help.
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="Final_Year_Project_Allocation_System.silviomoreto_bootstrap_select_d4ec9bd.WebForm1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="http://code.jquery.com/jquery-latest.js" type="text/javascript"></script>
<link href="bootstrap-select.css" rel="stylesheet" type="text/css" />
<link href="bootstrap-select.css" rel="stylesheet" type="text/css" />
<script src="../bootstrap/js/bootstrap.js" type="text/javascript"></script>
<script src="bootstrap-select.js" type="text/javascript"></script>
</head>
<body>
<form id="form1" runat="server" >
<div>
<select class="selectpicker">
<option>Mustard</option>
<option>Ketchup</option>
<option>Relish</option>
</select>
</div>
</form>
</body>
</html>
please help.
I don't see a reference to the actual bootstrap.css ?
You need to have something like (note the order - it's important):
<link href="bootstrap.css" rel="stylesheet" type="text/css" />
<link href="bootstrap-select.css" rel="stylesheet" type="text/css" />
Then the JS
<script src="../bootstrap/js/bootstrap.js" type="text/javascript"></script>
<script src="../bootstrap/js/bootstrap-select.js" type="text/javascript"></script>
Make sure the path is correct of course.
EDIT
I'm also pretty sure that boostrap.js has a dependency on jquery - so make sure you include it as well (before the bootsrap.js).
EDIT 2
I also suspect that your paths are not correct. If this is the path for your javascript:
"../bootstrap/js/bootstrap.js"
Then most probably the path for your css would be (assuming that you just dropped bootstrap as-is and didn't place it in a different folder):
"../bootstrap/css/bootstrap.css"

The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>)

I am stuck with this error and found a work around and the solutions works for me, but i i would like to know is it the best way to fix the issue and i want to make sure that it wont affect any other pages badly. Hope the experts will help.
If this was the best solution then many of you can save your heads.
This error occurs when a code block is placed in the MasterPage. Place the code block in a placeholder to resolve the issue.When adding AJAX extenders to your Web page, it will attempt to register scripts in the head. If code blocks are present in the MasterPage, an error might occur.
To resolve this issue, simply move the code block into a placeholder in the head of your MasterPage, like so:
<head id="Head1" runat="server">
<title>Untitled Page</title>
<link href="StyleSheet.css" rel="stylesheet" type="text/css" />
<asp:ContentPlaceHolder ID="myPlaceholder" runat="server">
<script language="javascript" type="text/javascript" src="<%= Page.ResolveClientURL("~/javascript/global.js")%>"></script>
</asp:ContentPlaceHolder>
<asp:ContentPlaceHolder ID="head" runat="server"></asp:ContentPlaceHolder>
</head>
The error is logical you can not confuse the rendered controls after they rendered by using the <%= %>
One way to solve this issue is to use a literal control, and render the script line on code behind.
<asp:ContentPlaceHolder ID="myPlaceholder" runat="server">
<asp:Literal runat="server" ID="txtIncludeScript" EnableViewState="false"></asp:Literal>
</asp:ContentPlaceHolder>
and on code behind. Check for null because if you change the placeholder the literal is null. Also set EnableViewState=false because you set it on every Page_Load and you do not wish to save it to viewstate.
if(txtIncludeScript != null)
{
txtIncludeScript.Text =
string.Format("<script language=\"javascript\" type=\"text/javascript\" src=\"{0}\"></script>",
Page.ResolveClientUrl("~/javascript/global.js"));
}
ContentPlaceHolder requires a master page, so you can replace that tag with some other element that can be ran at the server in case your page does not have a master page and you cannot get rid of the
<head id="Head1" runat="server">
<title>Untitled Page</title>
<link href="StyleSheet.css" rel="stylesheet" type="text/css" />
<div runat="server">
<script language="javascript" type="text/javascript" src="<%= Page.ResolveClientURL("~/javascript/global.js")%>"></script>
</div>
<asp:ContentPlaceHolder ID="head" runat="server"></asp:ContentPlaceHolder>
</head>

Problem with loading CSS while invoking page by Server.Transfer()

While I'm using Response.Redirect("~/Pages/Page.aspx"), style is loaded on the page, but unfortunately it is not loaded while I'm using Server.Transfer("~/Pages/Page.aspx") method.
The page looks following:
<html>
<head runat="server">
<link href="../Css/Layout/style.css" type="text/css" rel="stylesheet" />
</head>
<body></body>
</html>
How to make the page load style.css using Server.Transfer() ?
Regards
The problem is that you use a relative path to your CSS file, you should use an abolute path.
If the css folder is inside your application root, you can use
<html>
<head runat="server">
<link href="/Css/Layout/style.css" type="text/css" rel="stylesheet" />
</head>
<body></body>
</html>
or even
<html>
<head runat="server">
<link href="~/Css/Layout/style.css" type="text/css" rel="stylesheet" runat="server" ID="aUniqueId" />
</head>
<body></body>
</html>

Categories

Resources