Click here to Skip to main content
15,878,809 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi everyone,

I have 2 questions and i`d be greatful if anyone could help me

1) Iam using a ajax post request

C#
   var xhr = false;
   if (window.XMLHttpRequest) { xhr = new XMLHttpRequest(); }
   else { xhr = new ActiveXObject("Microsoft.XMLHTTP"); }
   xhr.onreadystatechange = function () {
      if (xhr.readyState == 4 && xhr.status == 200) {
         var grid = $("#grid1");
         grid.parentNode.innerHTML = xhr.responseText;
      }
   }
   
   var url = "jquegrid.aspx";
   xhr.open("POST", url, false);

   xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
   //xhr.setRequestHeader("IsLookup", "true");
   xhr.send(sendData);
   return false;
}


and on server side i want to find which columns are visible using reflection
via code
C#
public List<PropertyInfo> GetPropertyListFromGrid<T2>(GridView objGrid)
{
   List<PropertyInfo> lsproperties = new List<PropertyInfo>();
          
   int columnIndex = -1;
   foreach (TableCell cell in objGrid.Rows[2].Cells)
   {
      columnIndex++;
      foreach (Control childControl in cell.Controls)
      {
         Type type = childControl.GetType();

         string CtrlName = type.Name;
         if (CtrlName == "TextBox" || CtrlName == "CheckBox")
         {
            bool isEnabled = (bool)type.GetProperty("Enabled").GetValue(childControl, null);
            bool isVisible = (bool)type.GetProperty("Visible").GetValue(childControl, null);
               
            if (isEnabled && isVisible )
            {
               //do something
            }
         }
      }
   }
          
   return lsproperties;
}



but (bool)type.GetProperty("Visible").GetValue(childControl, null);
always returns false,when using ajax request,but if iam using a callback server,i`m able to get the value of visible property.Please Help me out.


2)there is some rendering issue with the editable columns rendering in IE8 browser,sometimes,columns in a grid`s row get distorted,but when i get next set of result using ajax and goes back,everything appear normal.

Waiting for a positive reply from experts.
Thanks

Update
Please reply for 2nd question.
Posted
Updated 11-Nov-14 7:32am
v4

1 solution

Try this way:

C#
    Type controlType = childControl.GetType();
// Get PropertyInfo describing the property
    PropertyInfo propertyInfo = controlType.GetProperty("Enabled");
    // Get actual value from the control object
    object val = propertyInfo.GetValue(control);
    bool isEnabled = (bool) val;

    propertyInfo = controlType.GetProperty("Visible");
    // Get actual value from the control object
    val = propertyInfo.GetValue(control);
    bool isVisible = (bool) val; 
 
Share this answer
 
Comments
Member 10582972 11-Nov-14 13:31pm    
Thanks for Reply.
i`m not able to see any difference between my code
<pre lang="c#"> bool isEnabled = (bool)type.GetProperty("Enabled").GetValue(childControl, null);
bool isVisible = (bool)type.GetProperty("Visible").GetValue(childControl, null);</pre>
and your`s code
<pre lang="c#">PropertyInfo propertyInfo = controlType.GetProperty("Enabled");
// Get actual value from the control object
object val = propertyInfo.GetValue(control);
bool isEnabled = (bool) val;

propertyInfo = controlType.GetProperty("Visible");
// Get actual value from the control object
val = propertyInfo.GetValue(control);
bool isVisible = (bool) val; </pre>

both is the same code,only style of writing is different
and also GetValue Method cannot take 1 parameter in c# 4.0
Kuthuparakkal 11-Nov-14 14:11pm    
it's working code; also you may try to see if PropertyInfo is null before getting the value. Thats the difference. Splitting into many would be easy to debug.

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