When ever i run this code, the BlockUI message will first show when the "Opdater_Click" has runned. (And would just be stuck there even tho Unblock is being called in the end.
I am trying to block my UI when the button is pushed, when the UI is blocked, it's setting up the DataSource, and when that is done, the UI should be unblocked.
I'v tried to put a timeout in, think that the Block command might need time, but that is not the case.
Anyone has any suggestions on what the problem might be?
Javascriptcode in ASPX file
<script src="JavaScript/jquery-2.1.4.min.js"></script>
<script src="JavaScript/jquery.blockUI.js"></script>
<script type="text/javascript">
function block() { $.blockUI({ message: "halp" });}
function unblock() { $.bunlockUI();}
</script>
C# code
protected void Opdater_Click(object sender, EventArgs e) {
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "sometihg", "block();", true);
Frontsite.DataSource = DL.GetWetmixBatches(calStart.SelectedDate, calStop.SelectedDate, null, null, null, null, null, null, null, null, null);
Frontsite.DataBind();
System.Diagnostics.Debug.WriteLine("Have no clue");
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "sometihg", "unblock();", true);
}
Okay, first of all, doing this server-side does not get you the result you want.
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "sometihg", "block();", true);
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "sometihg", "unblock();", true);
This just means that when the server is done with the Opdater_Click function, that he will incredibly fast block everything and then unblock it again. This has no use. You should trigger the block() function from your html/javascript yourself. Remember that the C# code is executed on the server and only when it has completed, it returns something to the browser. So this would effectivly return: "block();unblock()", which is not what you want, because your user can just keep clicking on the button until the server side action returns.
I think your problem will be solved by simply moving the block function to your HTML/Javascript. It's fine to have the unblock function run only after the server side operation has completed.
You could do this with jQuery for instance.
$( "#target" ).click(function() {
block();
});
EDIT
Also, I think it didn't work in the first place because you called RegisterClientScriptBlock with the same key two times. The "sometigh" is supposed to be unique. I'm not exactly sure what happens when you call it with twice the same key.