简体   繁体   中英

When alert box is popped up, the backgroung goes blank

My website is in .net framework 2.0. I'm using alert as well as confirm dialog box provided by javascript.

What issue I'm facing is when alert box is popped up, the background goes blank and user can not view on what things he/she was working.

While the same is not happening with confirm dialog box. As my application is in 2.0, I'm not able to find the appropriate solution for that.

Now my ques is why confirm dialog box is displaying the background but alert is not and what changes I shall make so that I can view the background in case of alert box also?

Here are the code snippets:

When I'm using the below confirm dialog box I can view the background:

btnDeleteGroup.Attributes.Add("onclick","javascript:return confirm('Are you sure you want to delete this group?');");
btnTemplateDelete.Attributes.Add("onclick","javascript:return confirm('Are you sure you want to delete this template?');");

Below is the code for alert dialog box. I want the alert box to be popped when my list is empty:

private void AddRecipients(String text, ListBox listBox)
{
    ListItemCollection items = new ListItemCollection();
    AddRecipientToList(text, items);

    // No matching recipients
    if (items.Count == 0)
    {
        BrowserMessage("There are no users or groups with this name");         
        return;
}

// Exactly one match found
if (items.Count == 1)
{
    listBox.Items.Add(items[0]);
    return;
} 
}

The BrowseMessage function is defined as shown below:

public void BrowserMessage(string Message)
{
    Message = Message.Replace("\"", "'").Replace(@"\", @"\\").Replace("\n", @"\n");
    OutputJavascript("alert(\""+ Message + "\");");
} 

and the OutputJavascript is defined as :

public void OutputJavascript(String script)
{
    ScriptBlock js = new ScriptBlock(this);
    js.AddScript(script);
    js.Register();
}

Please let me know if any extra information is required for the above problem.

Here is the design code for. the alert needs to be popped up when the user clicks Add receipient button

<DIV 
STYLE="DISPLAY: inline; Z-INDEX: 100; LEFT: 8px; WIDTH: 72px; POSITION: absolute; TOP: 8px; HEIGHT: 21px" 
MS_POSITIONING="FlowLayout">Subject</DIV>
<DIV 
STYLE="DISPLAY: inline; Z-INDEX: 104; LEFT: 8px; WIDTH: 72px; POSITION: absolute; TOP: 64px; HEIGHT: 21px" 
MS_POSITIONING="FlowLayout">Message</DIV><asp:image id="Image1" style="Z-INDEX: 106;  LEFT: 368px; POSITION: absolute; TOP: 72px" runat="server" ToolTip="Required field"   ImageUrl="..\images\redLed.gif"></asp:image><asp:image id="Image2" style="Z-INDEX: 107; LEFT: 304px; POSITION: absolute; TOP: 40px" runat="server" ToolTip="Required field" ImageUrl="..\images\redLed.gif"></asp:image></DIV>
<DIV CLASS="groupbox" 
STYLE="Z-INDEX: 110; LEFT: 8px; WIDTH: 328px; POSITION: absolute; TOP: 56px; HEIGHT: 248px" 
MS_POSITIONING="GridLayout"><asp:ListBox id="lbRecipients" style="Z-INDEX: 101; LEFT: 8px; POSITION: absolute; TOP: 56px" tabIndex="3" runat="server" Width="312px"    CssClass="formtextbox" EnableViewState="False" Height="153px" SelectionMode="Multiple">    
</asp:ListBox>   
 **<asp:Button id="btnRecipientAdd" style="Z-INDEX: 102; LEFT: 216px; POSITION: absolute; TOP: 32px" runat="server" Width="102px" CssClass="formbutton" CausesValidation="False" Text="Add Recipient" EnableViewState="False">    </asp:Button>**

Below is the generated HTML

<script language='javascript'> 
function TabStrip1_Click(index)
{
var f=document.forms[0];
f['TabStrip1_Index'].value=index;
f.submit();
}
</script>
<script language="Javascript"><!--
alert("There are no users or groups with this name");//--></script>
<script language="javascript"><!--
function showMessage(postValue)
{
var f=document.forms[0];
f.__MESSAGENUMBER.value=postValue;
f.submit();
}
//--></script>
<script language="javascript"><!--
function saveRecipients()
{
listSaveContents('lbRecipients', '__RECIPIENTS');
}
//--></script>
<script language="javascript"><!--
function addRecipient(sText,sValue)
{
var op=gE('lbRecipients').options;
op[op.length]=new Option(sText,sValue);
}

Your cs seems like a very strange way of outputting a javascript alert... Try this:

public void BrowserMessage(string Message)
{
    Message = Message.Replace(@"\", @"\\").Replace("\n", @"\n");
    OutputJavascript(Message);
} 
public void OutputJavascript(String message)
{
    string output = @"<script language='javascript'> alert('"+message+"');</script>";
    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "UserPopup", output);
}

You're doing a postback to generate this message, which then gets rendered into the page as it reloads. It's rendered straight inline, not as a method, so it is invoked as the page is loading. Thus, the alert is encountered while the browser is parsing the page for render, it shows the alert , and puts a pause on further parsing and rendering.

You would probably be better off just putting this as a label underneath your recipients box, and just put in the message and coloring it red on the postback.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM