I have a button that executes code behind in c#. The code behind gets some information from the database and writes a fairly long piece of JavaScript that it then registers and runs on the client. The code behind looks something like this:
protected void Button1_Click(object sender, EventArgs e)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append(@"
<script language='javascript'>
//Lots of JavaScript
</script>");
System.Web.UI.ScriptManager.RegisterStartupScript(this, this.GetType(), "JCall1", sb.ToString(), false);
}
The code works and does what it should. The problem is between the press of the button and the execution of the JavaScript, I get a page reload flash. I would like to stop that flash. I can tell it is happening before the JavaScript executes because one of the first things I do in the JavaScript is start a processing icon. It spins while some promises are resolved/handled. The flash occurs before the icon starts processing. Once the JavaScript starts (icon appears and spins), everything is good. It is probably something I don't understand in the lifecycle of this button. I'm surmising that when I RegisterStartupScript, the page is refreshing to load the new script. I can't do it all in JavaScript Client-Side because internal data needs to be provided to the API's. Yes, it would be great if the site was .Net Core and I could do it all in a Razor Page but this is not what I am dealing with. It's WebForms. There may not be anything I can do about it but if there is, I could use some help.