Browse Source

2006-11-19 Igor Zelmanovich <[email protected]>

	* TemplateControlCompiler.cs: fixed:
	When <%# Bind(...) %>-expression is used more then once for same control
	The variable associated with this control is declared only once.


svn path=/trunk/mcs/; revision=68150
Igor Zelmanovich 19 years ago
parent
commit
368eb80064

+ 6 - 0
mcs/class/System.Web/System.Web.Compilation/ChangeLog

@@ -1,3 +1,9 @@
+2006-11-19 Igor Zelmanovich <[email protected]>
+
+	* TemplateControlCompiler.cs: fixed:
+	When <%# Bind(...) %>-expression is used more then once for same control
+	The variable associated with this control is declared only once.
+
 2006-11-18  Marek Habersack  <[email protected]>
 
 	* AppResourceFilesCompiler.cs: Fixed an exception thrown when

+ 30 - 16
mcs/class/System.Web/System.Web.Compilation/TemplateControlCompiler.cs

@@ -1034,27 +1034,40 @@ namespace System.Web.Compilation
 			CodeVariableReferenceExpression tableExp = new CodeVariableReferenceExpression ("__table");
 			
 			if (builder.Bindings != null) {
+				Hashtable hash = new Hashtable ();
 				foreach (TemplateBinding binding in builder.Bindings) {
-					CodeVariableDeclarationStatement dec = new CodeVariableDeclarationStatement (binding.ControlType, binding.ControlId);
-					method.Statements.Add (dec);
-					CodeVariableReferenceExpression cter = new CodeVariableReferenceExpression ("__container");
-					CodeMethodInvokeExpression invoke = new CodeMethodInvokeExpression (cter, "FindControl");
-					invoke.Parameters.Add (new CodePrimitiveExpression (binding.ControlId));
-					
-					CodeAssignStatement assign = new CodeAssignStatement ();
-					CodeVariableReferenceExpression control = new CodeVariableReferenceExpression (binding.ControlId); 
-					assign.Left = control;
-					assign.Right = new CodeCastExpression (binding.ControlType, invoke);
-					method.Statements.Add (assign);
-					
-					CodeConditionStatement sif = new CodeConditionStatement ();
-					sif.Condition = new CodeBinaryOperatorExpression (control, CodeBinaryOperatorType.IdentityInequality, new CodePrimitiveExpression (null));
-					
+					CodeConditionStatement sif;
+					CodeVariableReferenceExpression control;
+					CodeAssignStatement assign;
+
+					if (hash [binding.ControlId] == null) {
+
+						CodeVariableDeclarationStatement dec = new CodeVariableDeclarationStatement (binding.ControlType, binding.ControlId);
+						method.Statements.Add (dec);
+						CodeVariableReferenceExpression cter = new CodeVariableReferenceExpression ("__container");
+						CodeMethodInvokeExpression invoke = new CodeMethodInvokeExpression (cter, "FindControl");
+						invoke.Parameters.Add (new CodePrimitiveExpression (binding.ControlId));
+
+						assign = new CodeAssignStatement ();
+						control = new CodeVariableReferenceExpression (binding.ControlId);
+						assign.Left = control;
+						assign.Right = new CodeCastExpression (binding.ControlType, invoke);
+						method.Statements.Add (assign);
+
+						sif = new CodeConditionStatement ();
+						sif.Condition = new CodeBinaryOperatorExpression (control, CodeBinaryOperatorType.IdentityInequality, new CodePrimitiveExpression (null));
+
+						method.Statements.Add (sif);
+
+						hash [binding.ControlId] = sif;
+					}
+
+					sif = (CodeConditionStatement) hash [binding.ControlId];
+					control = new CodeVariableReferenceExpression (binding.ControlId);
 					assign = new CodeAssignStatement ();
 					assign.Left = new CodeIndexerExpression (tableExp, new CodePrimitiveExpression (binding.FieldName));
 					assign.Right = new CodePropertyReferenceExpression (control, binding.ControlProperty);
 					sif.TrueStatements.Add (assign);
-					method.Statements.Add (sif);
 				}
 			}
 
@@ -1706,3 +1719,4 @@ namespace System.Web.Compilation
 }
 
 
+