tags:

views:

19

answers:

1

I have a form with multiple rows of text boxes. I use jquery .show() and .hide() to dynamically add or remove a textbox.

In my codebehind, I retrieve a myReport object and based on the number of entries, I want to display or hide the right number of text boxes.

I can use .visible = true / false but that removes the element from the page so that the jquery functions no longer work.

I tried using

.class.add('visibility', 'hidden')

but even with this, the jquery .show() function fails to make the textbox visible.

Is there a way I can call a jquery function from code behind or an attribute that I can add to a text box to make it invisible and still work with .show() method

A: 
$("yourtextboxselector").css({'display': 'none'});

You can check the visibility using :visible

$("yourtextboxselector").is(":visible");

You can set the display attribute in C# also

txtBox.Style["display"] = "none";
rahul
and then how can I check in jquery if css property display is not none
TP
isn't that the equivalent of `$('selector').hide();` ?
RPM1984
@TP - use `$('selector').is(":visible")`
RPM1984
No. .hide() does not set display to none. it does some other weird thing. if you have 'display:none' or 'visibility:hidden' set, then .show() will not make the element visible for some reason
TP
So here is my actual issue then. I call txtBox.style["display"] = "inline" in my page load method since I want the box to be visible. (they are all hidden by default) but the jquery function to hide them is in (document).ready() so it overrides what the codebehind did. Is there any workaround for that?
TP
Do you want to make the textboxes visible or hidden after page load?
rahul
And also what do you mean by "hidden by default". Do you set that?
rahul
yes. i hide them by default. I found a workaround. From the code behind, I set the number of rows visible to a hidden textbox and the the jquery reads the textbox value and makes the appropriate number of boxes visible
TP