Reputation: 107
<script language="javascript">
res = "&res="+screen.width+"x"+screen.height+"&d="+screen.colorDepth
top.location.href="Login.aspx?action=set"+res
</script>
Source Error:
An unhandled exception was generated during the execution of the current web request,Information regarding origin and location exception can be identified using the exception stact trace below.
Stack trace:
[Null ReferenceException: object reference not set to an instance of an object.]
page_Load(object sender EventArgs e)+143
and next from System.Web
Based on screen resolution iam setting a login web page. How do I avoid null reference exception?
Upvotes: 0
Views: 934
Reputation: 388
You should probably look at using a flow based page layout that automatically adjusts. However, I have had to do something similar in the past, and the trick is to place the resize code in a timeout:
setTimeout(function() {
res = "&res="+screen.width+"x"+screen.height+"&d="+screen.colorDepth
top.location.href="Login.aspx?action=set"+res
}, 0);
This is required because script code does not execute deterministically. Sometimes it will run before the screen dimensions have been calculated and populated. Other Ajax toolkits such as jQuery handle this exact problem by placing page init code in a special onLoad handler.
Upvotes: 1