C# Corner
Tech
News
Videos
Forums
Trainings
Books
Events
More
Interviews
Jobs
Live
Learn
Career
Members
Blogs
Challenges
Certifications
Bounties
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Access Control Id on Client Side with or Without using Master Page
WhatsApp
Gaurav Kumar
5y
9.7
k
0
1
25
Blog
Here is the method through which you can access Asp.net control's Id using javascript.
When you are working on a simple form.
Let's suppose you want to make a textbox clear or blank on a button click on client-side
HTML
<asp:TextBox ID=
"txtPassword"
runat=
"server"
TextMode=
"Password"
></asp:TextBox>
Put below javascript code in the <head></head> section of the form:
<script type=
"text/javascript"
>
function
clrCtrl() {
document.getElementById(
'txtPassword'
).value =
""
;
}
</script>
On button's OnClientClick event we can use clrCtrl() function.
When you are using Master Page
When you are using Master Page, you just need to change the javascript code like below and out it in
Content Section:
<asp:Content ID=
"Content1"
ContentPlaceHolderID=
"ContentPlaceHolder1"
runat=
"Server"
>
<script type=
"text/javascript"
>
function
clrCtrl() {
document.getElementById(
'<%=txtPassword.ClientID%>'
).value =
""
;
}
</script>
// here you html code begins
</asp:Content>
People also reading
Membership not found