Solved

ASP Static Method Access Page Control?

Posted on 2013-11-13
2
1,474 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…

690 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