Reputation: 429
I have strange problem with Javascript, I am trying to implement system to update some stuff, and when I press button I want to hide everything except 'MainContent_UpdateProgress', but text area is still visible.
Text area in asp.net looks like this:
<textarea runat="server" id="serverOutputTextArea" cols="50" rows="30" name="serverOutputTextArea" visible="false">
Javascript code:
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_initializeRequest(InitializeRequest);
prm.add_endRequest(EndRequest);
var postBackElement;
function InitializeRequest(sender, args) {
if (prm.get_isInAsyncPostBack())
args.set_cancel(true);
postBackElement = args.get_postBackElement();
if (postBackElement.id == 'MainContent_UpdateAnalysisSystem')
{
$get('MainContent_serverOutputTextArea').style.display = 'none'; //Doesn't work
$get('MainContent_UpdateProgress').style.display = 'block'; //Works
$get('MainContent_ProcessingStatus_Label').style.display = 'none'; //Works
$get('MainContent_ShowDetails_Button').style.display = 'none'; //Works
}
}
Question would be, what is different in textarea ?
Upvotes: 0
Views: 550
Reputation: 1746
Have you looked in the browser's source code to see what the actual id of the textarea is? It might be that you have it placed within some other element and it has inherited a longer id.
Otherwise, you can get the id by using this: <%= serverOutputTextArea.ClientID%>
The javascript line would look like this:
$get('<%= serverOutputTextArea.ClientID %>').style.display = 'none';
Upvotes: 2
Reputation: 8474
Just to confirm: Is MainContent_serverOutputTextArea the id of the textarea?
If yes, can you go to Firebug and try setting the display style attribute to none? Or out of despair try visibility=hidden.
But ultimately, you need to make sure that $get is selecting the correct element in the DOM.
Mmmmm... I think I know what's going on. You have:
<textarea runat="server" id="serverOutputTextArea" ... visible="false">
You added the runat="server" to the textarea so it'll be a server control and if the Visible property is false, it simply won't be rendered to the HTML.
Do you know what this means? If it's not rendered, your JavaScript won't be able to see it and select. Set the Visible property to true and it will work.
Upvotes: 1