Click here to Skip to main content
15,905,967 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
In the below code when the dialog box opens, the background page disappears.
kindly help

for (int i = 1; i <= list.Count; i++)
{
if (list[i] == list[i - 1])
{
ClientScript.RegisterClientScriptBlock(GetType(), "Javascript",
"<script>alert('Record Added Successfully')</script>");
//Page.ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('Enter unique values');", true);
}
}
Posted
Comments
Sinisa Hajnal 5-Feb-15 2:22am    
What do you mean disappears? There is nothing on the page as if the rendering stopped? Do you see any error in the console? Why are you doing it like this (I'm guessing this is not complete code)? I would put an information box somewhere on the page and put a message into the label instead of sending alerts, but I did it with clientscript and had no trouble. Please check that everything works as expected (put Try Catch around for loop)
Member 10578683 5-Feb-15 2:59am    
I want to say that when the alert box appears then the main page on which this appears is blank. i.e on a blank white page the alert box appears. when i am clicking the ok button of alert box then the main page appears. i want to see the main page always
Sinisa Hajnal 5-Feb-15 3:14am    
The script runs as soon as it is rendered. It stops rendering the rest of the page until you click OK.

Make client side function and call it on page ready. In the register script simply set some variable that you can check in the function to know if you should show the message.

1 solution

In page header have:
HTML
<script type="text/javascript">
    var recordAddedSuccess = false;
</script>

This can be anywhere on the page as long as it is UNDER recordAddedSuccess definition.
<script type="text/javascript">
function showMessage() {
    if (recordsAddedSuccess)
        alert('Record Added Successfully');
// reset the variable
    recordsAddedSuccess = false;
}

// this assumes jQuery...if you don't use it, use window.onload event
$(document).ready(function() { showMessage(); });
</script>



In your register script server side, set recordAddedSuccess = true; When the page loads, the method will execute and your message will be shown.


If this helps please take time to accept the solution. Thank you.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900