Q: Please tell me why this is not working.

  • Thread starter Visual Systems AB \(Martin Arvidsson\)
  • Start date
V

Visual Systems AB \(Martin Arvidsson\)

Hi!

Enclosed code gives me a compiler error with the text

"Argument '1': cannot convert from 'System.Web.UI.ControlCollection' to
'System.Web.UI.Control'" and also

"The best overloaded method match for
'ArchitectDev.custdetail.AssignJavaScript(System.Web.UI.Control)' has some
invalid arguments"

<--- CODE START --->
private void AssignJavaScript(System.Web.UI.Control ctrl)
{
foreach(System.Web.UI.Control c in ctrl.Controls)
{
if(c is TextBox)
{
((TextBox)c).Attributes.Add("OnChange", "DoChange");
}
AssignJavaScript(c);
}
}
private void Page_Prerender(object sender, System.EventArgs e)
{
AssignJavaScript(this.Controls);
}
<---CODE END -->

Just cant understand why, its the this.Controls it doesn't like...

How can i add the Page_Prerender to the PreRender event?
Do i have to do it manually or can i select the function in a property
editor?

Should i set this in Page_Load?

Regards
Martin Arvidsson
 
K

Karl Seguin

this.Controls a ControlCollection, simply pass "this" since in your
AssignJavaScript function you are looking through the controlcollection of
the control you passed in.

Karl
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top