2
<script type="text/javascript">     
    var BrowserCompt = document.documentMode;
    document.getElementById("<%=hddnBrowserComp.ClientID %>").value = BrowserCompt;
    alert(BrowserCompt);
</script>

I want to use this hiddenfield(hddnBrowserComp) value on my page load , but it is coming blank. How can i achieve the same?

C#
if(!IsPostBack)
{
string x ="";
x = hddnBrowserComp.Value.ToString();
}
Parimal Raj
  • 20,189
  • 9
  • 73
  • 110
rohit singh
  • 550
  • 1
  • 11
  • 32
  • 2
    You won't be able to do what you're trying to do using the code above as JavaScript executes on the client and your C# code executes on the server. Because of server --send to--> client, your C# code is executed first (and has no awareness that on the client side you're setting that hidden field value, unless you post back) and the hidden field is blank. Based on what you're trying to do with document.documentMode, [this](http://stackoverflow.com/questions/9430449/can-i-detect-ie-document-mode-on-the-server-side-using-the-httpbrowsercapabiliti) previous question may help you.... – nkvu Mar 30 '13 at 05:49

4 Answers4

2

It is never going to work that way, as server side code executes first then client side code.

Nilesh Thakkar
  • 2,877
  • 1
  • 24
  • 43
0

Remove !IsPostBack

You have !IsPostBack. So You got this problem. 1st remove that then try .

string x ="";
x = hddnBrowserComp.Value.ToString();
Ramesh Rajendran
  • 37,412
  • 45
  • 153
  • 234
0
documentMode property only supported in the IE...documentMode property it returns the following value based on the IE versions

5

Internet Explorer 5 mode (also known as "quirks mode").

7

Internet Explorer 7 Standards mode.

8

Internet Explorer 8 Standards mode.

9

Internet Explorer 9 Standards mode.

10

Internet Explorer 10 Standards mode.
0
if(!isPostback)    
{        
  string x ="";
  x = hddnBrowserComp.Value.ToString();

  ScriptManager.RegisterClientScriptBlock(this, GetType(), "Done", "alert('" + x+"');", true);

}

try this it will work

Aijaz Chauhan
  • 1,511
  • 3
  • 25
  • 53