2

I have these textboxes:

<asp:Label ID="lbllastname" runat="server" Text="LastName" 
     CssClass="labels" />&nbsp;
<asp:TextBox ID="txtlastname" runat="server" CssClass="texts"
     onkeyup="firstElementPress(event);" TabIndex="3" />
<br />
<asp:Label ID="lblfirstname" runat="server" Text="FirstName" 
     CssClass="labels" />&nbsp;
<asp:TextBox ID="txtfirstname" runat="server" CssClass="texts"
      onkeyup="firstElementPress(event);" TabIndex="4" />
<br />
<asp:Label ID="lblmi" runat="server" Text="MI" CssClass="labels" />&nbsp;
<asp:TextBox ID="txtmi" runat="server" CssClass="texts"
      onkeyup="firstElementPress(event);" TabIndex="5" />
<br />
<asp:Label ID="lblext" runat="server" Text="Suffix" CssClass="labels" />&nbsp;
<asp:TextBox ID="txtext" runat="server" CssClass="texts"
     onkeyup="firstElementPress(event);" TabIndex="6" />

CSS:

.labels
{
    font: bold 10pt Calibri;
    color: Black;
}

.texts
{
    border-color: Black;
    border-width: thin;
    height: 16px;
    font: 10pt Calibri;
}

They're fine but if the user encounters the javascript alert when the name already exists, these textboxes lose their height and the border thickens. I have no idea why this is happening.

Here's the code for the alert:

Response.Write("<script>alert('The name you specified already exists!');
                </script>");

Why is this happening? I don't think it has something to do with the javascript on the onkeyup event. Or maybe it does? IDK. It just places the focus on different controls.

In any case, here's the Javascript for it:

function firstElementPress(e) {
    if (e.keyCode == 27) {
        document.getElementById('fuso').focus();
    }
    if (e.keyCode == 17) {
        document.getElementById('txtso').focus();
    }
}

I wish someone would explain to me why this happens. Thanks!

4

1 回答 1

1

尝试这个... :

提示信息如下:

 Page.ClientScript.RegisterStartupScript(this.GetType(), "alertmesg", "<script language=javascript> alert('The name you specified already exists!');</script>");

反对

Response.Write("<script>alert('The name you specified already exists!');</script>");

谢谢...

于 2013-10-24T08:57:42.923 回答