Relation between .cs file and .aspx

Posted by SurajRane under ASP.NET on 6/15/2010 | Views : 13630 | Status : [Member] | Replies : 8
Hi,

I know that,

.aspx file inherits from its code behind file. but how we are able to access controls which are defined in markup (.aspx file) in .cs file ?




Responses

Posted by: Vuyiswamb on: 6/15/2010 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down
Very good Question

Even the Page code behind inherit the cs file like this

: System.Web.UI.Page


Thank you for posting at Dotnetfunda
[Administrator]

SurajRane, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Muhilan on: 6/16/2010 [Member] Starter

Up
0
Down
in markup (.aspx file) controls should be in runat='server' then only you can access the particular control.

ex..

<input id="textbox" name="textbox1" />

the above html control you cant access in .cs file but you can access in javascript function.

<input id="textbox" name="textbox1" runat="server" />

you can access in .cs file and javascript also.


SurajRane, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: SurajRane on: 6/16/2010 [Member] Starter

Up
0
Down
I got the answer.

Actually when we add control with runat="server" it is added in

designer.cs file. This file contain class which is the same class which your page inherits.

designer.cs and codebehind files will be merged at runtime (as both have partial class definition) into single one.

Hence we are able to access controls added in aspx markup with rinat="server" in codebehind.


Thanks for the reply for my forum guys.[I really need to brush up my knowledge again. really :) ]


SurajRane, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: ANU_DGR8 on: 7/28/2010 [Member] Starter

Up
0
Down
@VUYISWAMB: I Dint get your reply

Thanks and Regards,
Hoosha Boosha

SurajRane, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vuyiswamb on: 7/28/2010 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down
Good day ANU_DGR8

on which reply ?

Thank you for posting at Dotnetfunda
[Administrator]

SurajRane, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: ANU_DGR8 on: 7/28/2010 [Member] Starter

Up
0
Down
Gud Day!
The answer that you have given for this question

Thanks and Regards,
Hoosha Boosha

SurajRane, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vuyiswamb on: 7/28/2010 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down
In order to Find controls in asp.net you need to use this


Page.FindControl("ControlID");


Thank you for posting at Dotnetfunda
[Administrator]

SurajRane, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: ANU_DGR8 on: 7/28/2010 [Member] Starter

Up
0
Down
But the question asked is How are we able to access controls in (.aspx) in cs file?

Thanks and Regards,
Hoosha Boosha

SurajRane, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response