InvokeMethod...? 
Author Message
 InvokeMethod...?

Hi!

    ASP.NET and C#

    I have 10 labels (label1, label2, labeln, ...)(<asp:label> controls)...
*I need to modify the labelx.Font.Bold property of one of these label but I
never know wich one it's gonna be*.. I've looked at the InvokeMethod sample
in the MSDN and I didn't understand much of it... can I call a control with
a string value (like: "label" + iLabelIndex.ToString()) ? Is the
InvokeMethod the right method? I don't want to call a method I'd like to
get/set an object property.

    TIA

--
Best Regards
Zoury
_________________________________
Thanks to post replies to the newsgroup :O)



Tue, 19 Apr 2005 05:46:41 GMT  
 InvokeMethod...?
try using the FindControl method - here's some sample code from the
documentation to get you started:

private void Button1_Click(object sender, EventArgs MyEventArgs)
{
      // Find control on page.
      Control myControl1 = FindControl("TextBox2");
      if(myControl1!=null)
      {
         // Get control's parent.
         Control myControl2 = myControl1.Parent;
         Response.Write("Parent of the text box is : " + myControl2.ID);
      }
      else
      {
         Response.Write("Control not found");
      }

Quote:
}

--

-----------------------
This posting is provided "AS IS" with no warranties, and confers no rights


Quote:
> Hi!

>     ASP.NET and C#

>     I have 10 labels (label1, label2, labeln, ...)(<asp:label>
controls)...
> *I need to modify the labelx.Font.Bold property of one of these label but
I
> never know wich one it's gonna be*.. I've looked at the InvokeMethod
sample
> in the MSDN and I didn't understand much of it... can I call a control
with
> a string value (like: "label" + iLabelIndex.ToString()) ? Is the
> InvokeMethod the right method? I don't want to call a method I'd like to
> get/set an object property.

>     TIA

> --
> Best Regards
> Zoury
> _________________________________
> Thanks to post replies to the newsgroup :O)



Tue, 19 Apr 2005 06:18:46 GMT  
 InvokeMethod...?
That should work fine! Thanks a lot! ;O)

--
Best Regards
Zoury
_________________________________
Thanks to post replies to the newsgroup :O)


Quote:
> try using the FindControl method - here's some sample code from the
> documentation to get you started:

> private void Button1_Click(object sender, EventArgs MyEventArgs)
> {
>       // Find control on page.
>       Control myControl1 = FindControl("TextBox2");
>       if(myControl1!=null)
>       {
>          // Get control's parent.
>          Control myControl2 = myControl1.Parent;
>          Response.Write("Parent of the text box is : " + myControl2.ID);
>       }
>       else
>       {
>          Response.Write("Control not found");
>       }
> }

> --

> -----------------------
> This posting is provided "AS IS" with no warranties, and confers no rights



> > Hi!

> >     ASP.NET and C#

> >     I have 10 labels (label1, label2, labeln, ...)(<asp:label>
> controls)...
> > *I need to modify the labelx.Font.Bold property of one of these label
but
> I
> > never know wich one it's gonna be*.. I've looked at the InvokeMethod
> sample
> > in the MSDN and I didn't understand much of it... can I call a control
> with
> > a string value (like: "label" + iLabelIndex.ToString()) ? Is the
> > InvokeMethod the right method? I don't want to call a method I'd like to
> > get/set an object property.

> >     TIA

> > --
> > Best Regards
> > Zoury
> > _________________________________
> > Thanks to post replies to the newsgroup :O)



Tue, 19 Apr 2005 06:30:04 GMT  
 InvokeMethod...?

Quote:

>     I have 10 labels (label1, label2, labeln, ...)(<asp:label> controls)...
> *I need to modify the labelx.Font.Bold property of one of these label but I
> never know wich one it's gonna be*.. I've looked at the InvokeMethod sample
> in the MSDN and I didn't understand much of it... can I call a control with
> a string value (like: "label" + iLabelIndex.ToString()) ? Is the
> InvokeMethod the right method? I don't want to call a method I'd like to
> get/set an object property.

You'd be *much* better off having an array of labels instead:
label[0]
label[1]
etc

That way you'd just do:

label[iLabelIndex].Font.Bold=true;

or whatever.

Admittedly this will probably be harder to do with VS.NET's GUI builder -
and is a good example of where such things unfortunately come unstuck :(

--
Jon Skeet

If replying to the group, please do not mail me at the same time



Tue, 19 Apr 2005 06:46:03 GMT  
 InvokeMethod...?
Hi Jon!

I was wondering if there was some sort of Control Array in C#... is it
possible or you'd like too? <g>

ps: i'm working with webcontrols

--
Best Regards
Zoury
_________________________________
Thanks to post replies to the newsgroup :O)

Quote:

> >     I have 10 labels (label1, label2, labeln, ...)(<asp:label>
controls)...
> > *I need to modify the labelx.Font.Bold property of one of these label
but I
> > never know wich one it's gonna be*.. I've looked at the InvokeMethod
sample
> > in the MSDN and I didn't understand much of it... can I call a control
with
> > a string value (like: "label" + iLabelIndex.ToString()) ? Is the
> > InvokeMethod the right method? I don't want to call a method I'd like to
> > get/set an object property.

> You'd be *much* better off having an array of labels instead:
> label[0]
> label[1]
> etc

> That way you'd just do:

> label[iLabelIndex].Font.Bold=true;

> or whatever.

> Admittedly this will probably be harder to do with VS.NET's GUI builder -
> and is a good example of where such things unfortunately come unstuck :(

> --
> Jon Skeet

> If replying to the group, please do not mail me at the same time



Tue, 19 Apr 2005 06:55:43 GMT  
 InvokeMethod...?

Quote:

> I was wondering if there was some sort of Control Array in C#... is it
> possible or you'd like too? <g>

> ps: i'm working with webcontrols

I suspect it's not the kind of thing the builder has, but there's nothing
to stop you from just writing the code yourself...

--
Jon Skeet

If replying to the group, please do not mail me at the same time



Tue, 19 Apr 2005 07:54:46 GMT  
 InvokeMethod...?
ok... I've tried this:

for (int i = 1; i < 11;i++)
{
    Control ctl = lblStart.Parent.FindControl("lblPage" + i.ToString());

    iText = iLowerPage + i - 1;

    ctl.Text = iText.ToString();
    ctl.Font.Bold = (i == m_iCurPage);

Quote:
}

I got errors with the last two lines:

    System.Web.UI.Control' does not contain a definition for 'Text'
    System.Web.UI.Control' does not contain a definition for 'Font'

I've then tried to cast the Control type into a Label type but it didn't
work...

PLUS, my IDE don't break on breakpoints anymore. I've checked my
Configuration Manager and the project I'm working on is set to Debug. What
else should I check?

any helps would be greatly appreciated! thanks

--
Best Regards
Zoury
_________________________________
Thanks to post replies to the newsgroup :O)


Quote:
> That should work fine! Thanks a lot! ;O)

> --
> Best Regards
> Zoury
> _________________________________
> Thanks to post replies to the newsgroup :O)


> > try using the FindControl method - here's some sample code from the
> > documentation to get you started:

> > private void Button1_Click(object sender, EventArgs MyEventArgs)
> > {
> >       // Find control on page.
> >       Control myControl1 = FindControl("TextBox2");
> >       if(myControl1!=null)
> >       {
> >          // Get control's parent.
> >          Control myControl2 = myControl1.Parent;
> >          Response.Write("Parent of the text box is : " + myControl2.ID);
> >       }
> >       else
> >       {
> >          Response.Write("Control not found");
> >       }
> > }

> > --

> > -----------------------
> > This posting is provided "AS IS" with no warranties, and confers no
rights



> > > Hi!

> > >     ASP.NET and C#

> > >     I have 10 labels (label1, label2, labeln, ...)(<asp:label>
> > controls)...
> > > *I need to modify the labelx.Font.Bold property of one of these label
> but
> > I
> > > never know wich one it's gonna be*.. I've looked at the InvokeMethod
> > sample
> > > in the MSDN and I didn't understand much of it... can I call a control
> > with
> > > a string value (like: "label" + iLabelIndex.ToString()) ? Is the
> > > InvokeMethod the right method? I don't want to call a method I'd like
to
> > > get/set an object property.

> > >     TIA

> > > --
> > > Best Regards
> > > Zoury
> > > _________________________________
> > > Thanks to post replies to the newsgroup :O)



Tue, 19 Apr 2005 22:42:24 GMT  
 InvokeMethod...?
Ok I got it to work.. I used:

    Label lbl = (Label)lblStart.Parent.FindControl("lblPage" +
i.ToString());

but I still have my breakpoints problems.. :'O(

--
Best Regards
Zoury
_________________________________
Thanks to post replies to the newsgroup :O)

Quote:
> ok... I've tried this:

> for (int i = 1; i < 11;i++)
> {
>     Control ctl = lblStart.Parent.FindControl("lblPage" + i.ToString());

>     iText = iLowerPage + i - 1;

>     ctl.Text = iText.ToString();
>     ctl.Font.Bold = (i == m_iCurPage);
> }

> I got errors with the last two lines:

>     System.Web.UI.Control' does not contain a definition for 'Text'
>     System.Web.UI.Control' does not contain a definition for 'Font'

> I've then tried to cast the Control type into a Label type but it didn't
> work...

> PLUS, my IDE don't break on breakpoints anymore. I've checked my
> Configuration Manager and the project I'm working on is set to Debug. What
> else should I check?

> any helps would be greatly appreciated! thanks

> --
> Best Regards
> Zoury
> _________________________________
> Thanks to post replies to the newsgroup :O)



> > That should work fine! Thanks a lot! ;O)

> > --
> > Best Regards
> > Zoury
> > _________________________________
> > Thanks to post replies to the newsgroup :O)


> > > try using the FindControl method - here's some sample code from the
> > > documentation to get you started:

> > > private void Button1_Click(object sender, EventArgs MyEventArgs)
> > > {
> > >       // Find control on page.
> > >       Control myControl1 = FindControl("TextBox2");
> > >       if(myControl1!=null)
> > >       {
> > >          // Get control's parent.
> > >          Control myControl2 = myControl1.Parent;
> > >          Response.Write("Parent of the text box is : " +
myControl2.ID);
> > >       }
> > >       else
> > >       {
> > >          Response.Write("Control not found");
> > >       }
> > > }

> > > --

> > > -----------------------
> > > This posting is provided "AS IS" with no warranties, and confers no
> rights



> > > > Hi!

> > > >     ASP.NET and C#

> > > >     I have 10 labels (label1, label2, labeln, ...)(<asp:label>
> > > controls)...
> > > > *I need to modify the labelx.Font.Bold property of one of these
label
> > but
> > > I
> > > > never know wich one it's gonna be*.. I've looked at the InvokeMethod
> > > sample
> > > > in the MSDN and I didn't understand much of it... can I call a
control
> > > with
> > > > a string value (like: "label" + iLabelIndex.ToString()) ? Is the
> > > > InvokeMethod the right method? I don't want to call a method I'd
like
> to
> > > > get/set an object property.

> > > >     TIA

> > > > --
> > > > Best Regards
> > > > Zoury
> > > > _________________________________
> > > > Thanks to post replies to the newsgroup :O)



Tue, 19 Apr 2005 22:47:12 GMT  
 InvokeMethod...?
Strangely, when I start another project (either Windows Application, Console
or ASP.NET) it does break on breakpoint... how come?

--
Best Regards
Zoury
_________________________________
Thanks to post replies to the newsgroup :O)

Quote:
> Ok I got it to work.. I used:

>     Label lbl = (Label)lblStart.Parent.FindControl("lblPage" +
> i.ToString());

> but I still have my breakpoints problems.. :'O(

> --
> Best Regards
> Zoury
> _________________________________
> Thanks to post replies to the newsgroup :O)


> > ok... I've tried this:

> > for (int i = 1; i < 11;i++)
> > {
> >     Control ctl = lblStart.Parent.FindControl("lblPage" + i.ToString());

> >     iText = iLowerPage + i - 1;

> >     ctl.Text = iText.ToString();
> >     ctl.Font.Bold = (i == m_iCurPage);
> > }

> > I got errors with the last two lines:

> >     System.Web.UI.Control' does not contain a definition for 'Text'
> >     System.Web.UI.Control' does not contain a definition for 'Font'

> > I've then tried to cast the Control type into a Label type but it didn't
> > work...

> > PLUS, my IDE don't break on breakpoints anymore. I've checked my
> > Configuration Manager and the project I'm working on is set to Debug.
What
> > else should I check?

> > any helps would be greatly appreciated! thanks

> > --
> > Best Regards
> > Zoury
> > _________________________________
> > Thanks to post replies to the newsgroup :O)



> > > That should work fine! Thanks a lot! ;O)

> > > --
> > > Best Regards
> > > Zoury
> > > _________________________________
> > > Thanks to post replies to the newsgroup :O)


> > > > try using the FindControl method - here's some sample code from the
> > > > documentation to get you started:

> > > > private void Button1_Click(object sender, EventArgs MyEventArgs)
> > > > {
> > > >       // Find control on page.
> > > >       Control myControl1 = FindControl("TextBox2");
> > > >       if(myControl1!=null)
> > > >       {
> > > >          // Get control's parent.
> > > >          Control myControl2 = myControl1.Parent;
> > > >          Response.Write("Parent of the text box is : " +
> myControl2.ID);
> > > >       }
> > > >       else
> > > >       {
> > > >          Response.Write("Control not found");
> > > >       }
> > > > }

> > > > --

> > > > -----------------------
> > > > This posting is provided "AS IS" with no warranties, and confers no
> > rights



> > > > > Hi!

> > > > >     ASP.NET and C#

> > > > >     I have 10 labels (label1, label2, labeln, ...)(<asp:label>
> > > > controls)...
> > > > > *I need to modify the labelx.Font.Bold property of one of these
> label
> > > but
> > > > I
> > > > > never know wich one it's gonna be*.. I've looked at the
InvokeMethod
> > > > sample
> > > > > in the MSDN and I didn't understand much of it... can I call a
> control
> > > > with
> > > > > a string value (like: "label" + iLabelIndex.ToString()) ? Is the
> > > > > InvokeMethod the right method? I don't want to call a method I'd
> like
> > to
> > > > > get/set an object property.

> > > > >     TIA

> > > > > --
> > > > > Best Regards
> > > > > Zoury
> > > > > _________________________________
> > > > > Thanks to post replies to the newsgroup :O)



Wed, 20 Apr 2005 02:44:36 GMT  
 InvokeMethod...?
Am not sure what why your breakpoints should stop working for this
situation.
Check
http://www.*-*-*.com/
blems.doc for information on de{*filter*} issues. Hopefully the help on ASP.NET
debugging should come useful.

-Swati

-----------------------
This posting is provided "AS IS" with no warranties, and confers no rights

Quote:
> Strangely, when I start another project (either Windows Application,
Console
> or ASP.NET) it does break on breakpoint... how come?

> --
> Best Regards
> Zoury
> _________________________________
> Thanks to post replies to the newsgroup :O)


> > Ok I got it to work.. I used:

> >     Label lbl = (Label)lblStart.Parent.FindControl("lblPage" +
> > i.ToString());

> > but I still have my breakpoints problems.. :'O(

> > --
> > Best Regards
> > Zoury
> > _________________________________
> > Thanks to post replies to the newsgroup :O)


> > > ok... I've tried this:

> > > for (int i = 1; i < 11;i++)
> > > {
> > >     Control ctl = lblStart.Parent.FindControl("lblPage" +
i.ToString());

> > >     iText = iLowerPage + i - 1;

> > >     ctl.Text = iText.ToString();
> > >     ctl.Font.Bold = (i == m_iCurPage);
> > > }

> > > I got errors with the last two lines:

> > >     System.Web.UI.Control' does not contain a definition for 'Text'
> > >     System.Web.UI.Control' does not contain a definition for 'Font'

> > > I've then tried to cast the Control type into a Label type but it
didn't
> > > work...

> > > PLUS, my IDE don't break on breakpoints anymore. I've checked my
> > > Configuration Manager and the project I'm working on is set to Debug.
> What
> > > else should I check?

> > > any helps would be greatly appreciated! thanks

> > > --
> > > Best Regards
> > > Zoury
> > > _________________________________
> > > Thanks to post replies to the newsgroup :O)



> > > > That should work fine! Thanks a lot! ;O)

> > > > --
> > > > Best Regards
> > > > Zoury
> > > > _________________________________
> > > > Thanks to post replies to the newsgroup :O)


> > > > > try using the FindControl method - here's some sample code from
the
> > > > > documentation to get you started:

> > > > > private void Button1_Click(object sender, EventArgs MyEventArgs)
> > > > > {
> > > > >       // Find control on page.
> > > > >       Control myControl1 = FindControl("TextBox2");
> > > > >       if(myControl1!=null)
> > > > >       {
> > > > >          // Get control's parent.
> > > > >          Control myControl2 = myControl1.Parent;
> > > > >          Response.Write("Parent of the text box is : " +
> > myControl2.ID);
> > > > >       }
> > > > >       else
> > > > >       {
> > > > >          Response.Write("Control not found");
> > > > >       }
> > > > > }

> > > > > --

> > > > > -----------------------
> > > > > This posting is provided "AS IS" with no warranties, and confers
no
> > > rights



> > > > > > Hi!

> > > > > >     ASP.NET and C#

> > > > > >     I have 10 labels (label1, label2, labeln, ...)(<asp:label>
> > > > > controls)...
> > > > > > *I need to modify the labelx.Font.Bold property of one of these
> > label
> > > > but
> > > > > I
> > > > > > never know wich one it's gonna be*.. I've looked at the
> InvokeMethod
> > > > > sample
> > > > > > in the MSDN and I didn't understand much of it... can I call a
> > control
> > > > > with
> > > > > > a string value (like: "label" + iLabelIndex.ToString()) ? Is the
> > > > > > InvokeMethod the right method? I don't want to call a method I'd
> > like
> > > to
> > > > > > get/set an object property.

> > > > > >     TIA

> > > > > > --
> > > > > > Best Regards
> > > > > > Zoury
> > > > > > _________________________________
> > > > > > Thanks to post replies to the newsgroup :O)



Sun, 01 May 2005 06:39:49 GMT  
 
 [ 10 post ] 

 Relevant Pages 

1. Privilege not held on InvokeMethod

 

 
Powered by phpBB® Forum Software