Click here to Skip to main content
15,892,809 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I would like to know how to change the TextMode asp textbox property (Singleline,multiline,password)in javascript.Is there any possibility.
Posted

Try this
Javascript
XML
<script type="text/javascript">
       function test() {
           document.getElementById('<%= txt.ClientID %>').type = 'password';
       }
   </script>


Design Part
XML
<asp:TextBox ID="txt"  runat="server" TextMode="SingleLine"></asp:TextBox>
 <div  onclick="test();" >click</div>
 
Share this answer
 
Here is the solution,

<div>
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</div>
<script type="text/javascript">
    var obj = document.getElementById("TextBox1");
    var newObj = document.createElement('input');
    newObj.setAttribute('type', 'password');
    newObj.setAttribute('id', obj.getAttribute('id'));
    newObj.setAttribute('name', obj.getAttribute('name'));
    obj.parentNode.replaceChild(newObj, obj);
    newObj.focus();
</script>


The basic idea is to create a new element with your desired textmode and replace the original with the new one.

Hope this helps.
cheers
 
Share this answer
 
v2
Comments
saeed1364 27-Aug-12 0:51am    
PLEASE BETTER Explain .WHAT INPUT
IN EXMPLE Explain .
<asp:TextBox ID="TPassUser" runat="server" Width="250px" CssClass="FormTableTextBox" Height="18px" onkeydown="return (event.keyCode!=13);"
MaxLength="150" AutoPostBack="false" TabIndex="1" TextMode="Password">
pradiprenushe 27-Aug-12 2:39am    
Try my below answer.
 
Share this answer
 
Comments
Member 9603723 10-Jan-13 3:51am    
AaA
Member 9603723 10-Jan-13 3:51am    
AaA
I think if you change the TextMode property of a Textbox web control client side you will get a failed viewstate error on postback.

I would either create all three controls on the page and only display one at a time based on some user action.

or

Create plain html controls with no runat="server" on them and manipulate their attributes with jquery.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900