Click here to Skip to main content
13,288,520 members (58,797 online)
Click here to Skip to main content
Add your own
alternative version


4 bookmarked
Posted 26 Aug 2010

Using C# code inside JavaScript code

, 26 Aug 2010
Rate this:
Please Sign up or sign in to vote.
if you are working in a page that has a master page, and you want to reference the server controls from JavaScript you must use their ClientID instead of the ID property, so in order to use C# code within JavaScript code, you will have to surround your C# code with the <%= and %>, and this is the example.

var txtBox = document.getElementById(‘<%=txtName.ClientID%>’); 

remember this code is available only if your JavaScript code was in an .aspx file not a .js file


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


About the Author

Software Developer Asset Technology Group
Egypt Egypt
I'm a professional components designer, web developer, UX engineer and 3d designer as well, I'm 4 years experienced .net software engineer and 7 years experienced 3d designer using 3D Max. I'm very interested in RIA technologies, prototyping and UX engineering.

Ahmed Said
Senior .Net Software Engineer

You may also be interested in...


Comments and Discussions

QuestionNice Ya Man Pin
Eng Kerollos Adel18-May-15 3:23
groupEng Kerollos Adel18-May-15 3:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.171207.1 | Last Updated 26 Aug 2010
Article Copyright 2010 by Ahmed_Said
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid