Tarang
Tarang

Reputation: 66

\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

Upvotes: 0

Views: 204

Answers (3)

Tushar Gupta
Tushar Gupta

Reputation: 15923

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");

Upvotes: 1

Please try with Environment.NewLine for VB.net

as below:

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

will return

[First
Second]

Upvotes: 0

jan
jan

Reputation: 875

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

Upvotes: 0

Related Questions