1
votes

I am using Asp.net c# with javascript
I want use the Session value in javascript so am using this code:

<script type="text/javascript">
    var Warehousename = '<%= Session["warehouse_id"] %>';
    var temp = new Array();
    temp = Warehousename.split(",");
    if (temp.length > 1) {
        alert('you have multiple access of warehouse. Kindly select the only one warehouse from Preference')
        window.location.href = "frm_preferences.aspx";
    }
</script>

But am facing some error like

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

So where am doing wrong please suggest me

1
Where is this code? in the head section?Divyang Desai
Yes this code in head sectionATT

1 Answers

2
votes

Here are possible solutions:

First :
Remove JavaScript from the header section of page and add it to body of the page and run your application it will work for you!

Second :

Replace the code block with <%# instead of <%=

After replace code block with <%# instead of <%= add following code in page load

protected void Page_Load(object sender, EventArgs e)
{
  Page.Header.DataBind();    
}