开发者

I am trying to hide text in a ASPX page that is tied to a textbox

So there is a a table and a text box in one of the cells

<td>
    <asp:TextBox ID="tbSomeTextBox" Columns="5" runat="server"> % 
</td>

This textbox gets shown if a certain selection is made in a drop down. The problem is that I would like the "%" character to also be hidden or shown with the textbox.

I have tried putting t开发者_JAVA百科he whole textbox control inside a DIVand in my JQuery hiding the DIV at the same time I hid the textbox.

<td>
    <div id="divSomeDIV"><asp:TextBox ID="tbSomeTextBox" Columns="5" runat="server"> % </div
</td>

But I get an error in my java script that id="divSomeDIV" doesn't exist in the current context.

$("#<%=divSomeDiv.ClientID%>").hide();

Wrapping that single character in a asp:Label seems like overkill.

Any suggestions?


divSomeDiv is running client-side (i.e. no "runat=server"), so there's no need for

$("#<%=divSomeDiv.ClientID%>").hide();

Just do

$("#divSomeDiv").hide();


create an asp.net label, set the label value to be %, and make them both visible or both not visible at the same time... ?


If you were getting "does not exist" in your Javascript it's probably because your Javascript is running before the div is created in the dom. In other words, this is incorrect.

<script>$("#divSomeDiv").hide()</script>
<div id="divSomeDiv">...</div>

You can either put the Javascript after the div

<div id="divSomeDiv">...</div>
<script>$("#divSomeDiv").hide()</script>

Or you can make your Javascript run after the DOM has loaded.

<script>
  $(function() {
    $("#divSomeDiv").hide()
  });
</script>
<div id="divSomeDiv">...</div>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜