how can i access HTML controls in C# code file without using "runat=server" option in control. Is this possible? For Eg. I have declare a html control 'Select' and i want to fill it using C# code file. How to do this , please provide solution.
how can i access HTML controls in C# code file without using "runat=server" option in control. Is this possible?
Not sure why you mind having the attribute... but the answer is NO, it is not possible.
The "runat" attribute is used to "run a control at the server" - which means if you don't specify it, the control does not exist on the server side. Therefore you cannot use FindControl as one poster suggested.
Using JavaScript on the client-side might allow you to do whatever it was you intended to do with C#, but that wasn't really your question..!
"Man is the Only Animal that Blushes. Or needs to." (Mark Twain)
Remember to "mark as answer" any relevant and useful posts!
string strValue = Page.Request.Form["name of the control"].ToString();
The question was strictly speaking how to access a control - this of course gets a string represenation of the
value of an INPUT control when a form is posted. But as we don't know what the asker is actually trying to accomplish it may be a useful tip! It certainly does not require any runat attribute, since it works directly with the request without
any object model of the page's controls.
"Man is the Only Animal that Blushes. Or needs to." (Mark Twain)
Remember to "mark as answer" any relevant and useful posts!
bubbly
Member
3 Points
52 Posts
How to Access Html controls in C# code
Sep 02, 2008 07:27 AM|LINK
hi all,
how can i access HTML controls in C# code file without using "runat=server" option in control. Is this possible? For Eg. I have declare a html control 'Select' and i want to fill it using C# code file. How to do this , please provide solution.
Thank you,
-Bubbly
ankit.sri
Contributor
2042 Points
410 Posts
Re: How to Access Html controls in C# code
Sep 02, 2008 08:01 AM|LINK
try something like this:
WebControl myControlControl = (WebControl)Page.FindControl(CONTROLNAME);
susmitadeb
Participant
1052 Points
184 Posts
Re: How to Access Html controls in C# code
Sep 02, 2008 08:30 AM|LINK
Hi ,
You can try with the below code :
string strValue = Page.Request.Form["name of the control"].ToString();
Note:
1. The tag should have an attribute called NAME. Because it is used as key in form[].
2. The form method type should be POST, but not GET.
Hope this will help you.
hakeemkazmi
Member
60 Points
14 Posts
Re: How to Access Html controls in C# code
Sep 02, 2008 08:30 AM|LINK
use javascript to do that
Hakeem Kazmi
Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members reading the thread.
mydreams
Member
194 Points
83 Posts
Re: How to Access Html controls in C# code
Sep 02, 2008 08:40 AM|LINK
Using ASP.NET AJAX to solve it.
Talib_dotnet
Contributor
2162 Points
458 Posts
Re: How to Access Html controls in C# code
Sep 02, 2008 09:11 AM|LINK
Hi you can do it in this way ...
In your HTML Markup Page,
<
select id="SEL" name="SEL"> </select>In your Code-Behind Page,
Assign the value of Select as per your requirement
For eg.,string
str = Request.Form["SEL"];Hope this helps you....
Chief Technology Architect
MCTS
OnlineASP.Net
A-S-P Arabia...Consult Us
Talib_dotnet
Contributor
2162 Points
458 Posts
Re: How to Access Html controls in C# code
Sep 02, 2008 09:11 AM|LINK
Hi you can do it in this way ...
In your HTML Markup Page,
<
select id="SEL" name="SEL"> </select>In your Code-Behind Page,
Assign the value of Select as per your requirement
For eg.,string
str = Request.Form["SEL"];Hope this helps you....
Chief Technology Architect
MCTS
OnlineASP.Net
A-S-P Arabia...Consult Us
redbull2
Participant
1851 Points
355 Posts
Re: How to Access Html controls in C# code
Sep 02, 2008 09:12 AM|LINK
Not sure why you mind having the attribute... but the answer is NO, it is not possible.
The "runat" attribute is used to "run a control at the server" - which means if you don't specify it, the control does not exist on the server side. Therefore you cannot use FindControl as one poster suggested.
Using JavaScript on the client-side might allow you to do whatever it was you intended to do with C#, but that wasn't really your question..!
Remember to "mark as answer" any relevant and useful posts!
redbull2
Participant
1851 Points
355 Posts
Re: How to Access Html controls in C# code
Sep 02, 2008 09:16 AM|LINK
The question was strictly speaking how to access a control - this of course gets a string represenation of the value of an INPUT control when a form is posted. But as we don't know what the asker is actually trying to accomplish it may be a useful tip! It certainly does not require any runat attribute, since it works directly with the request without any object model of the page's controls.
Remember to "mark as answer" any relevant and useful posts!
bubbly
Member
3 Points
52 Posts
Re: How to Access Html controls in C# code
Sep 02, 2008 09:31 AM|LINK
hey i tried this but got exception "System.NullReferenceException: Object reference not set to an instance of an object." why this?
-Bubbly