admin管理员组文章数量:1299985
I've a .Net application wherein one of my pages, during initial page load, I'm setting the text of an asp label control. In my aspx page, I've a Javascript function to read the label text and show a confirmation pop-up message. The problem is, "\n" with in the label text is not introducing a line break in the JS confirmation message.
My Code Behind
lblMsg.Text = "string1" + "\n" + "string2"
Aspx Page
function PendingDeleteValidate() {
var x = document.getElementById("<%=lblMsg.ClientID%>");
if (confirm(x.innerHTML))
return true;
else
return false;
}
The JS confirmation dialog message shows:
string1\nstring2
I need to show a line break between the two strings.
I've a .Net application wherein one of my pages, during initial page load, I'm setting the text of an asp label control. In my aspx page, I've a Javascript function to read the label text and show a confirmation pop-up message. The problem is, "\n" with in the label text is not introducing a line break in the JS confirmation message.
My Code Behind
lblMsg.Text = "string1" + "\n" + "string2"
Aspx Page
function PendingDeleteValidate() {
var x = document.getElementById("<%=lblMsg.ClientID%>");
if (confirm(x.innerHTML))
return true;
else
return false;
}
The JS confirmation dialog message shows:
string1\nstring2
I need to show a line break between the two strings.
Share Improve this question edited Aug 29, 2020 at 22:21 Daniel Manta 6,71817 gold badges42 silver badges48 bronze badges asked Apr 30, 2013 at 19:19 Test_UserTest_User 1711 gold badge6 silver badges16 bronze badges 1-
Does the confirmation dialog have to get its text from a label? The problem is you're using
innerHTML
andwindow.confirm
doesn't know what to do with the HTML. It reads the\n
as just two characters like any others. – Heretic Monkey Commented Apr 30, 2013 at 19:32
3 Answers
Reset to default 5Try "\r\n \r\n"
after title text.
function myFunction() {
confirm("Tittle of DialogBox \r\n \r\nMessage of dialogbox. bla..bla.. bla... bla... bla..");
}
Fiddle Demo
Set like this in code behind:
lblMsg.Text = "string1" + "<br/>" + "string2"
And this
if (confirm(x.innerHTML))
to this
if (confirm(x.innerText))
why not try this i always use it
\\n also it would be wise to replace \r with ""
like this , have fun
and if you are only showing alerts with javascript then here is my function:
StringBuilder sb = new StringBuilder();
sb.Append("alert('");
sb.Append(msg.Replace("\n", "\\n").Replace("\r", "").Replace("'", "\\'"));
sb.Append("');");
return sb.ToString();
see if it works your needs. Regards
本文标签: cNew line in Javascript confirmation messageStack Overflow
版权声明:本文标题:c# - New line in Javascript confirmation message - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741656072a2390766.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论