我正在尝试获取要在警报消息上显示的textbox txtID的值。我使用以下代码来发出警报:
Response.Write("<script language='JavaScript' >alert('Record successfully added!');document.location='" + ResolveClientUrl("Siteindex.aspx") + "';</script>");它工作得很好,但是当我试图在警报中插入txtID的值时…
Response.Write("<script language='JavaScript' >alert('Record '" + txtID.Text + "' successfully added!');document.location='" + ResolveClientUrl("Siteindex.aspx") + "';</script>");未显示警报消息,但记录已添加。什么地方出问题了?我应该只使用另一个警报代码吗?
发布于 2013-11-17 07:47:40
转义字符串可能存在一些问题:
试着这样做
Response.Write("<script language=\"JavaScript\" >alert(Record " + txtID.Text + " successfully added!);document.location=" + ResolveClientUrl("Siteindex.aspx") + ";</script>");发布于 2013-11-17 08:22:40
你有一个额外的单引号,使用下面的代码
Response.Write("alert('Record“+ txtID.Text +”添加成功!‘);document.location=’“+ ResolveClientUrl("Siteindex.aspx") + "';");
发布于 2013-11-17 15:05:31
是否使用UpdatePanel包装“添加”按钮?如果是这样的话,您必须为该按钮设置PostBackTrigger。
我的意思是像下面这样的示例代码
<asp:UpdatePanel ID="UpdatePanel1" runat="server"><ContentTemplate>
<asp:TextBox ID="txtID" runat="server" ></asp:TextBox>
<asp:Button ID="btnAdd" runat="server" Text="Add" OnClick="btnAdd_Click" />
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="btnAdd" />
</Triggers>
</asp:UpdatePanel>其中,btnAdd按钮由btnAdd_Click处理,以添加记录并运行警报脚本
Response.Write("<script language='JavaScript' >alert('Record " + txtID.Text + " successfully added!');document.location='" + ResolveClientUrl("Siteindex.aspx") + "';</script>");https://stackoverflow.com/questions/20025283
复制相似问题