Click here to Skip to main content
15,888,454 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Quote:
The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).


I set the gridview on MasterPage and using JAVASCRIPT i want to do the task in which , when i click on the Row of gridview the value store into hidden flag and to what i want to do.

but the problem is when i debug the error is found
The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).




i writing this code//

from javascript...


C#
var curSelRowIndex = -1;
       var curSelRow = null;
       function GridDblClick(varRowIndex) {
           debugger;
           if (curSelRow != null) {
               curSelRow.style.backgroundColor = (curSelRowIndex % 2 == 0 ? "#EBEBEB" : "activeborder");
           }
           document.getElementById("<%=GridView1.ClientID %>").rows[varRowIndex].style.backgroundColor = '#ffc0cb';
           curSelRow = document.getElementById("<%=GridView1.ClientID %>").rows[varRowIndex];
           curSelRowIndex = varRowIndex;

           document.getElementById('<%=hidMID.ClientID %>').value = 'E~' + GetInnerText(document.getElementById("<%=GridView1.ClientID %>").rows[varRowIndex].cells[1]) + '~' + GetInnerText(document.getElementById("<%=GridView1.ClientID %>").rows[varRowIndex].cells[2]) + '~' + GetInnerText(document.getElementById("<%=GridView1.ClientID %>").rows[varRowIndex].cells[3]) + '~' + GetInnerText(document.getElementById("<%=GridView1.ClientID %>").rows[varRowIndex].cells[4]) + '~' + GetInnerText(document.getElementById("<%=GridView1.ClientID %>").rows[varRowIndex].cells[5]) + '~' + GetInnerText(document.getElementById("<%=GridView1.ClientID %>").rows[varRowIndex].cells[6]) + '~' + GetInnerText(document.getElementById("<%=GridView1.ClientID %>").rows[varRowIndex].cells[7]) + '~' + GetInnerText(document.getElementById("<%=GridView1.ClientID %>").rows[varRowIndex].cells[8]);

       }



on code behind .cs

C#
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
      {
          
          if (e.Row.RowIndex > -1)
          {
              e.Row.Attributes.Add("ondblclick", "javascript:return GridDblClick(" + (e.Row.RowIndex + 1) + ")");

          }
      }



THE MAIN THING IS I AM USING THIS CODE AND PLACE THIS GRIDVIEW ON MASTERPAGE.. PLZ SUGGEST ME WHAT I HAVE TO DO FOR THIS>>>
Posted
Comments
Aravindba 4-Feb-14 1:45am    
dont shout,remove all capital letters in ur description

one solution could try writing your javascript code in the body section html
 
Share this answer
 
Comments
Ravimcts 4-Feb-14 1:37am    
Dear, when i debug the javascript code then i found that this

var curSelRowIndex = -1;
var curSelRow = null;
function GridDblClick(varRowIndex) {
debugger;
if (curSelRow != null) {
curSelRow.style.backgroundColor = (curSelRowIndex % 2 == 0 ? "#EBEBEB" : "activeborder");
}
document.getElementById("").rows[varRowIndex].style.backgroundColor = '#ffc0cb';
curSelRow = document.getElementById("").rows[varRowIndex];
curSelRowIndex = varRowIndex;

document.getElementById('').value = 'E~' + GetInnerText(document.getElementById("").rows[varRowIndex].cells[1]) + '~' + GetInnerText(document.getElementById("").rows[varRowIndex].cells[2]) + '~' + GetInnerText(document.getElementById("").rows[varRowIndex].cells[3]) + '~' + GetInnerText(document.getElementById("").rows[varRowIndex].cells[4]) + '~' + GetInnerText(document.getElementById("").rows[varRowIndex].cells[5]) + '~' + GetInnerText(document.getElementById("").rows[varRowIndex].cells[6]) + '~' + GetInnerText(document.getElementById("").rows[varRowIndex].cells[7]) + '~' + GetInnerText(document.getElementById("").rows[varRowIndex].cells[8]);

}

means the HTML DOM part "document.getElementById("")" the control in this are not found. i try ur solution also but the same problm is there
tell me can i use the script i made on the master page also.
 
Share this answer
 
Comments
Ravimcts 4-Feb-14 2:24am    
i already go thru this solution sir. but this error is recoverd but main things is when i debug the code
document.getElementById("").rows[varRowIndex].style.backgroundColor = '#ffc0cb';

the id was not fetch by this..
what can i do now
JoCodes 4-Feb-14 2:31am    
But why you are using document.getElementById("") wihout any ID referred to fetch?
Ravimcts 4-Feb-14 2:38am    
then how can they identify the control. sir when i want any value from clientside then i used it and this works well also but i cant understand it may be due to Masterpage or any other problem.
plz suggest how can i identify the gridview control from client side.
i knw how to do this from server side but main issue is speed and reliability, plz tell me some more solution how can i get the value of control on client side
JoCodes 4-Feb-14 2:52am    
The way you accessing is correct , I asked because i saw document.getElementById("")<- no id was passed here. Can you check this link which pass the rowID concatenated with an id and passes to the client method to access it easily
http://stackoverflow.com/questions/7819638/how-to-change-the-gridview-row-colors-in-onclick-event-in-javascript
Ravimcts 4-Feb-14 2:58am    
ohh this comes when i debug the java script then i found that the id is not inside this ("").

i found problem but unable to resolve this, y this comes i make so many things wid javascript but i never used on master page i feel that i may be due to masterpage hmm/./

sir if u are getting my prblm its a humble rqst plz resolve it.
i dnt knw y r this occurs, their is no problm in code or any unwanted postbacks den y this occurs

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900