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>
No comments:
Post a Comment