Click here to Skip to main content
12,070,030 members (29,958 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# ASP.NET C#4.0
Hi all,

is there any way to access asp.net controls from Page methods(web methods).i am really stuck ma project in last couple of weeks..pleas help me..

Thanks n Advnce
Aatif Ali-Bangalore
Posted 11-Jun-13 20:33pm
Comments
Nandakishorerao 12-Jun-13 1:50am
   
no you cant access controls in webmethod. So, Create a class and load the values to its members.and create class instance and access the members.
Dhanesh P M 28-Oct-14 3:06am
   
Hi, I am also facing the same issue. if this problem fixed, can you please tell me how you solved it?
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  
v3
Comments
Aatif Ali from Bangalore 12-Jun-13 1:40am
   
hi friend,i think you are mistaken... i want to call page controls from web methods..not from normal c# methods..i will try different alternatives...but i unlucky...web methods s a static method ...thats the problem..
AYDIN EBRAHIMI HOMAY 12-Jun-13 1:50am
   
Ok Ali please give it me for thinking about, But I think try to change your solution ;)
AYDIN EBRAHIMI HOMAY 12-Jun-13 1:51am
   
Do you want to the find a control from asp.net web page?
Aatif Ali from Bangalore 12-Jun-13 2:21am
   
ya,sure..i want to find or accessing controls from a web method..in normal case it is easy to find out..but in web methods, i think it somewhat complex...
AYDIN EBRAHIMI HOMAY 12-Jun-13 4:37am
   
ya, you right if you are find a solution please tell me it is amazing for me ;)
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

var x=Page.FindControl("YourControlId");


for example:

var x=Page.FindControl("txtSample");
 
x.text="Sample text";

[edit]Code block added[/edit]
  Permalink  
v2
Comments
Aatif Ali from Bangalore 12-Jun-13 6:46am
   
check above solution and corresponding Comments...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web03 | 2.8.160208.1 | Last Updated 12 Jun 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100