简体   繁体   English

弹出警报框时,背景变为空白

[英]When alert box is popped up, the backgroung goes blank

My website is in .net framework 2.0. 我的网站在.net framework 2.0中。 I'm using alert as well as confirm dialog box provided by javascript. 我正在使用警报以及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. 由于我的应用程序是2.0版,因此无法找到合适的解决方案。

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: BrowseMessage函数的定义如下所示:

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

and the OutputJavascript is defined as : 并且OutputJavascript定义为:

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 下面是生成的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: 您的cs似乎是一种输出javascript警报的非常奇怪的方式...尝试以下操作:

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. 因此,在浏览器解析页面以进行渲染时会遇到alert ,它会显示alert ,并在进一步的解析和渲染时暂停。

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. 您最好将其作为标签放置在收件人框的下面,然后将邮件放入邮件并在回发邮件上将其涂成红色。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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