Reputation: 703
I have a DDL and Button which when clicked create a dynamic table; all controls are within an UpdatePanel
.
Outside the panel I have 2 buttons which should be hidden until the table is created.
If the buttons start as visible = false
and then I set them to true after I click the GO button from the UpdatePanel
, they never become visible
If I add a second UpdatePanel and put the 2 buttons in there it sort of works but I always get this error when clicking on either button:
Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerParserErrorException:
The message received from the server could not be parsed.
How to fix that?
Upvotes: 1
Views: 4143
Reputation: 13
Yes like Ashwin told you have to make the button visible from JS if you need the buttons outside the update panel. If you have scriptmanager in your page then you can call the JS function which make the buttons visible from codebehind like this
<script type="text/javascript" language="javascript">
function showButtons(){
document.getElementById("<%= Button1.ClientID %>").style.visibility = "visible";
document.getElementById("<%= Button2.ClientID %>").style.visibility = "visible";
}
</script>
If the button is a server control then get the client id of the button using the code block <%= %>. In the codebehind after creating the dynamic table use this
ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "showButtons", "showButtons();", true);
Upvotes: 0
Reputation: 7355
Move the two Buttons inside Update Panel. Only controls in the update panel get updated in an Ajax call. That is, if you want to alter any control's state through codebehind in an Ajax call you will have to include it inside your Update panel. You cannot change controls outside Update panel in an Ajax call.
UPDATE You need event handlers for this. Make the Button visible=true; and set their visibility:hidden, then change them as below when your call is completed.
<script type="text/javascript" language="javascript">
Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(beginRequestHandle);
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequestHandle);
function beginRequestHandle(sender, Args) {
//Do something when call begins.
}
function endRequestHandle(sender, Args) {
document.getElementById("Button1").style.visibility = "visible";
document.getElementById("Button2").style.visibility = "visible";
}
</script>
Upvotes: 3