简体   繁体   中英

\n or <br\> is not working in javascript

I am setting value of hiddenfield from code behind in vb.net

If(condition)
hdmodulename.Value =Dt_Module.DefaultView(0).Item("vModuleCode").ToString() +
 "-" + Dt_Module.DefaultView(0).Item("vModuleName").ToString()

Else

hdmodulename.Value = hdmodulename.Value + "'\n'" + Dt_Module.DefaultView(0).Item("vModuleCode").ToString() + "-" + Dt_Module.DefaultView(0).Item("vModuleName").ToString()
End If

now alert in javascript i code like below:

alert('You cannot select ' + document.getElementById('<%=hdmodulename.ClientID%>').value);

Output :

'\\n' is printed inseted of new line

so what is the probem?? Thanks A ton in advance

As for web pages, break lines with <br> or <p></p> tags. You can also Use Environment.NewLine with VB.

For JS use \\n' for the line break -

 alert("some text\\nmore text in a new line"); 

Not a vb expert, but shouldn't it be "\\n" instead of "'\\n'"? The one in the vb code have both double and single.

Please try with Environment.NewLine for VB.net

as below:

Dim value As String = "[First" + _
        Environment.NewLine + _
        "Second]"

will return

[First
Second]

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