Solved

ASP Static Method Access Page Control?

Posted on 2013-11-13
2
1,302 Views
Last Modified: 2013-11-16
I'm attempting to access a Page control and keep getting the ole "object instance error".

Q. How can I code this to work?

Page page = HttpContext.Current.Handler as Page;
Control ctl = page.FindControl("divError") as Control;
ctl.Controls.Add(new LiteralControl("<div style='color: red;'>" + ex.ToString() + "</div>"));
0
Comment
Question by:WorknHardr
2 Comments
 
LVL 16

Accepted Solution

by:
Kamal Khaleefa earned 300 total points
ID: 39647051
if the control in the same page then just call the control id and set the property

if the control in another page for example it is in your master page then use this


 Dim x As LinkButton = Me.Page.Master.FindControl("lnkHome")

where linkbutton is the type of your control(it might be a textbox , label ...etc)
0
 

Author Comment

by:WorknHardr
ID: 39647637
Are you saying that having the code inside a static method doesn't matter?
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now