FindControl doesn't work

D

Dennis

Gozirra said:
Here's what I did to find the a single label called Label1 on my page.
This code is in my page_load and obviously does nothing more than find
the control and write its ID to the page.

Dim lblTest As Label
lblTest = CType(Me.FindControl("Label1"), Label)
Response.Write(String.Format("Label ID using Me.FindControl is
{0}.", lblTest.ID))
Response.Write("<BR>")

lblTest = CType(Form1.FindControl("Label1"), Label)
Response.Write(String.Format("And the ID using Form1 is {0}.",
lblTest.ID))

Form1 is automatically included on any aspx page and is set as
runat="server". By default there is no declaration for this object and
there usually isn't a need for it. In the case of the sample code
above, I have declared Form1 as:
Protected Form1 As System.Web.UI.HtmlControls.HtmlForm

So in the first instance I used Me.FindControl to get a reference to
label1 and write its id. I then use the Form1 object to find the
control again and once again outputs its ID.

I hope this helps.

Thanks. I get an error "Name 'Form1' is not declared.", but if take
that out it works.

I figured out that the reason me.findcontrol doesn't work on my page is
because I'm using a master page.
 
D

Dennis

Gozirra - I hear McDonalds is hiring...but stay away from fries...
fries hot... But seriously... I hope this is for your home site and
that you don't actually get paid for your nonsense! The previous email
explaining that you should learn about the technology before stepping
off the cliff was a polite way of saying you are a moron. If stupidity
rules... you are the Emperor my friend! Good luck saying "hello to the
world."

At least I'm not a jackass like you.
 
M

michaelcoleman72

Dear SmartA$$ Dennis - When seeking trivial help on a forum with
smarta$$ responses like this:

"Kevin, I appreciate your reply, although I would've found it much more
helpful if you just answered my question (and it probably would've
taken you much less time). "

results in jacka$$ help for a really dumb smartA$$. Kevin gave you a
lesson in how to fish...not just lunch... I took it upon myself to hand
you your lunch...

Let me type slow so you will understand because large words might
offend your delicate persona... oh and make it real quick so you can
get back to your important work...

If you declare the following in markup in an aspx page...

<asp:Label ID="DitchDiggerDennis" runat="server" Text="I should be
digging a ditch for a tenth the of the money I make..." />
<asp:TextBox id="SanitationDeptIsHiring" runat="server" Text="Need
Help"></asp:TextBox>

you can reference then reference the control as follows:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load

SanitationDeptIsHiring.Text = DitchDiggerDennis.Text

End Sub

In closing... spend $0.50 of your overpaid salary and buy a 1.0 book.
You're giving other's in your so-called profession a bad name.

Sincerely
Jacka$$
 
D

Dennis

Thank you for proving my point.

Dear SmartA$$ Dennis - When seeking trivial help on a forum with
smarta$$ responses like this:

"Kevin, I appreciate your reply, although I would've found it much more
helpful if you just answered my question (and it probably would've
taken you much less time). "

results in jacka$$ help for a really dumb smartA$$. Kevin gave you a
lesson in how to fish...not just lunch... I took it upon myself to hand
you your lunch...

Let me type slow so you will understand because large words might
offend your delicate persona... oh and make it real quick so you can
get back to your important work...

If you declare the following in markup in an aspx page...

<asp:Label ID="DitchDiggerDennis" runat="server" Text="I should be
digging a ditch for a tenth the of the money I make..." />
<asp:TextBox id="SanitationDeptIsHiring" runat="server" Text="Need
Help"></asp:TextBox>

you can reference then reference the control as follows:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load

SanitationDeptIsHiring.Text = DitchDiggerDennis.Text

End Sub

In closing... spend $0.50 of your overpaid salary and buy a 1.0 book.
You're giving other's in your so-called profession a bad name.

Sincerely
Jacka$$
 
Joined
Jul 4, 2008
Messages
1
Reaction score
0
Please Try This...

Dim myControl1 As Control = FindControl("ctl00$ContentPlaceHolder1$TxtName1")
Dim txtNAme As TextBox = CType(FindControl("ctl00$ContentPlaceHolder1$TxtName1"), TextBox)



i think you may get how it can help for in your panel.

Follow these steps..
1-See panels clientID ( for exampl in my case "ctl00$ContentPlaceHolder1$TxtName1" is client id of my textbox. ( my page conten a masterpage then contentplaceholder then control)
.

master$contectplaceholder1$controlname
ctl00$ContentPlaceHolder1$TxtName1



regards
If still its not solve ..fire me a email..
Ajay
senior development Lead
 
Joined
Jul 1, 2009
Messages
1
Reaction score
0
My two cents

I know this is well after the original post but....
Dennis that was just rude.

Kevin, I appreciate your post, and if you get notification of this post....

A friend of mine who only spoke french wanted to learn english. He went to the library and got a bunch of kids books...in english. I'm now learning this new language of asp.net and wonder if you might be able to recommend some kids books on this language. I too, have been trying to run before I could walk and I've fallen flat on my face a few times. All the books and articles I read always seem to be a few grades above me. I do have bookmarked the links you posted earlier

Thanks

Bob
 
Joined
Apr 21, 2010
Messages
1
Reaction score
0
Looked this up and found your post, though I solved my problem it was pretty stupid. I didn't use asp:panel (WebControl). I was using the HtmlWebControl Panel! <Panel>.
 

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,774
Messages
2,569,596
Members
45,128
Latest member
ElwoodPhil
Top