the below js script works fine but there is small problem and the problem is that:
i have a textbox with multiline and when the user clicks on it and it does clear the textbox but the problem is; when the user click on Save button (asp.net control button) to save the textbox value and i want that to ignore on code behind and also client side.
one thing i can do is to compare the value and clear if it is matached but what if; if i have many controls and dont want to spread the string every where in the code…
looking for a optimized solution.
<asp:TextBox runat="server" ID="txtNew"
onclick="if (this.value == 'Enter here...') this.value = ''" TextMode="MultiLine"
Rows="7" Width="100%">Enter here...</asp:TextBox>
You don’t need to hardcode your
Enter here..., usedefaultValueinstead.For the codebehind part of your question:
I would recommend to use a
RequiredFieldValidator(since “Enter here” suggests that it’s mandatory). Then you can use theInititalValueproperty for your default text, hence the user must enter something to submit the page.