stuck on a problem to do with registering and then unregistering a block of javascript code. How can I unregister GRIDqrarefreshexposurereport?
- The below code will show a radio button list when the datasource of my grid is null.
-
Upon Selection, the page will refresh, the datasource and grid will be populated and the radio button list will be hidden due to GRIDqrarefreshexposurereport.
-
Upon clicking a cancel button, the datasource is set to null, the page is reloaded, the grid is empty and the radio button lists never appear even though they should.
Have debugged the code, and it runs through the correct blocks of code, however when I look at the source code of my ASP.net page both blocks of javascript are present, with the GRIDqrarefreshexposurereport block appearing last which is why i think the radio button list is not reappearing.
If anything is unclear I’ll do my best to clarify, any tips on how to make this clearer gladly taken.
if (gridExposureList.DataSource == null)
{
ClientScript.RegisterStartupScript(this.GetType(), "qrarefreshexposurereport", // Framework 2.0 conversion
@"<script language=""javascript"" type=""text/javascript"">
document.getElementById(""NoFilter"").style.display = ""None"";
document.getElementById(""RefreshEventsSummaryTiming"").style.display = ""none"";
document.getElementById(""RefreshEventsSummaryXPOS"").style.display = ""none"";
document.getElementById(""RefreshEventsSummaryFilter"").style.display = """";
document.getElementById(""QRAList"").style.display = ""none"";
document.getElementById(""RefreshExpRepFilter"").style.display = """";
document.getElementById(""GridButtons"").style.display = ""none"";
</script>
");
}
else
{
ClientScript.RegisterStartupScript(this.GetType(), "GRIDqrarefreshexposurereport", // Framework 2.0 conversion
@"<script language=""javascript"" type=""text/javascript"">
document.getElementById(""NoFilter"").style.display = ""None"";
document.getElementById(""RefreshEventsSummaryTiming"").style.display = ""none"";
document.getElementById(""RefreshEventsSummaryXPOS"").style.display = ""none"";
document.getElementById(""RefreshEventsSummaryFilter"").style.display = """";
document.getElementById(""QRAList"").style.display = ""none"";
document.getElementById(""RefreshExpRepFilter"").style.display = ""none"";
document.getElementById(""GridButtons"").style.display = """";
</script>
");
}
Since
ClientScript.RegisterStartupScriptmethod registers code block on every post back, there doesn’t seem any need to have unregister/deregister script block method. If you don’t want any code block to be registered, then just don’t register it.Just a guess, that the above code you pasted exists inside
Page_Loadmethod, if it is then it makes sense why you are having this problem, when post back occurs for settinggridExposureList.DataSourceto null,Page_Loadmethod is executed first and sincegridExposureList.DataSourceisn’t null yet it registersGRIDqrarefreshexposurereportand then calls the event for which the post back actually occurred… What you can do is, skip the above code in case of a post back and inside the event that set the database source of your gird to null, add the code to register the correct script block.