tags:

views:

56

answers:

3

In my C# asp.net 3.5 web application I am having controls like div tag inside that one textbox and one check box and the page is having a submit button. So in this submit button click I want to make the controls inside the div tag visible.. I am calling a JQuery function to do this. All the statements are getting executed but the control is not visible.. Following is the code in my JQuery function

$("input[name$='QuestionAndAnswerEditorDiv']").show();
$("input[name$='answerLabel1']").show()
$("input[name$='wmd-AnswerTextBox']").show() 

My div tag and its controls in the user control page are like the following

 <div id="QuestionAndAnswerEditorDiv" runat="server">
 <div id="wmd-button-bar" class="wmd-panel wmd-button-row"></div> 
 <textarea name="QuestionandAnswerTextArea" runat="server" id="AnswerTextBox" onkeyup="prettyPrint();" class="wmd-input editor" cols="92" rows="15"/><div class="wmd-preview text-preview preview" style="-ms-word-wrap: break-word;"></div>

As I noticed these controls are make visible=false in another page so they are not coming in the page source.. So Let me know how to work these controls now

A: 

all web server controls in asp.net < 4 are not rendered using their given name. to use the rendered name use Control.ClientID

Orentet
he is using the 'ends with' selector, so these will work
naspinski
+1  A: 

Setting QuestionAndAnswerEditorDiv.Visible = false; will mean that it doesn't get rendered to the page. In your code behind do the following:

QuestionAndAnswerEditorDiv.Attributes.Add("style", "display:none");
QuestionandAnswerTextArea.Attributes.Add("style", "display:none");

the JQuery show() function uses the display property and will set it to "block", which will make it visible.

Daniel Dyson
I tried this also but its also not working for me. I updated my question please take a look into it
stackuser1
@stackuser1 - If you continue to hide them on the server in the code-behind they will never show in the HTML source to make them visible on the client. Follow @Daniel Dyson's example above and replace your visible=false with his snippet.
Wallace Breza
A: 

This may not work because div is not going to render as input element and label is rendered as span element in asp.net so check for the type of controls

for div
$("div[name$='QuestionAndAnswerEditorDiv']").show();

for label
$("span[name$='answerLabel1']").show()

for textbox
$("input[name$='wmd-AnswerTextBox']").show() 

Edit :

so as i suggested in my answer make use of proper jquery selctor so that this will work for you

Edit 1

So rather than making control visible= false set there sytles to disply:none so that controls avaialbe on you page and you can play with them using jquery/javascript

Pranay Rana
y -1 ??????????????????
Pranay Rana