Solved

ASP Static Method Access Page Control?

Posted on 2013-11-13
2
1,383 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 Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Get number of Files in Directory and Sub Directories 2 48
FInd Image Control Gridview 3 19
Where is this file? 3 25
ASP.NET Content Page 3 25
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…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…

808 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