I call a JavaScript function in the page load
JScript File:
function fnCheckBrowserType()
{
if(navigator.appName == "Microsoft Internet Explorer" || navigator.appName == "Netscape")
{
document.all["HhdnBrowsertype"].value="1"
alert(document.getElementById("HhdnBrowsertype").value);
}
else
{
document.all["HhdnBrowsertype"].value="0"
alert(document.getElementById("HhdnBrowsertype").value);
}
}
ASP.NET code behind:
protected void Page_Init(object sender, EventArgs e)
{
Page.ClientScript.RegisterStartupScript(typeof(string), "fnCheckBrowserType", "fnCheckBrowserType();", true);
if (HhdnBrowsertype.Value.ToString() == "1")
{
int IE = 1;
}
else
{
int opera = 0;
}
}
HTML:
<script src="Browsers.js" type="text/javascript"></script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<%--<input id="HhdnBrowsertype" type="hidden" name="HhdnBrowsertype" runat="server" />--%>
<asp:HiddenField ID="HhdnBrowsertype" runat="server" />
</div>
</form>
</body>
In pageload, I call my javascript function here, I set the value of the hiddden field to "0" or "1", based on the type of browser, but when the page loads, the value of HhdnBrowsertype is always empty
Anyway, from javacript I return a value based on this value, I set my hidden field in the page load
Please help me on how I can return vlaue "0" or "1" from javscript to page load function
thank
source
share