p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   ASP.NET 2.0 Basics (http://p2p.wrox.com/forumdisplay.php?f=136)
-   -   HTML tag from C# or ASP.NET tag from javascript (http://p2p.wrox.com/showthread.php?t=54154)

angshujit February 16th, 2007 09:11 AM

HTML tag from C# or ASP.NET tag from javascript
 
Hello,
I have a problem.
I want to access HTML tag from C# code(hidden field).
or
I want to access ASP.NET tag from javascript.
Which one is possible and how?

Angshujit


dparsons February 16th, 2007 09:39 AM

To access the hidden field in code, add a runat=server attribute to the tag so: <input type=hidden name="hiddenfield" runat=server />

If you just want to get the value and don't want to manipulate the box in code you can do Request.Form("hiddenfield")

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html

angshujit February 16th, 2007 09:58 AM

Hello,
Thank you for your reply.
I have created a hidden field...

      <input type="hidden" id="action" runat="server" />

Then I have changed the value of the field from javascript(According to my choice). Then I have tried to access the value of the field from C# (on a button click event) ...

      string actn = Request.Form("action").Value;

But it is showing a error...
'System.Web.HttpRequest.Form' is a 'property' but is used like a 'method'

What to do?
Angshujit


dparsons February 16th, 2007 10:07 AM

This should work:

string actn = Convert.ToString(Request.Form.Get("action"));

Also, if you are using the above method, you do not need the runat=server attribute in the hidden field. The runat attribute is used to manipulate an HTML control in code, you are simply trying to get its value.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html


All times are GMT -4. The time now is 02:47 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.