Click here to Skip to main content
15,887,906 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey there, so i have a list of strings stored in a session (1 big list of names)
i would like to display these names in a javascript alertbox. i tried simple 'hello' and it worked. but then when i try to pass my session, the alert box does not display.

my code is below. please help guys thanks so much.



1.SESSION CONTAINS A LIST OF NAMES AS A STRING - POPULATED WITH ADIO.NET FROM SQL SERVER

2.BEHIND CODE
VB
protected Sub ShowMessage(sender As Object, e As EventArgs)

        'test works
        ' Dim message As String = "alert('test')"

        Dim message As String = "alert('" + Session("linkedSP").ToString() + "')"
        ScriptManager.RegisterClientScriptBlock(TryCast(sender, Control), Me.GetType(), "alert", message, True)
    End Sub


3.HTML
ASP.NET
<pre>  <asp:ImageButton ID="imbtnview" Width="20px" ToolTip="View service providers already linked to this user" ImageUrl="~/images/view.png" runat="server" OnClick="ShowMessage"/>


What I have tried:

VB
  Page.ClientScript.RegisterStartupScript(Me.GetType(), "alert", "showAlert(" + Session("linkedSP").ToString() + ");", True)

dim message = 'Alert(" + Session("linkedSP").ToString() + ")'



ScriptManager.RegisterClientScriptBlock(TryCast(sender, Control), Me.GetType(), "alert", message, True)
Posted
Updated 5-Apr-18 2:01am
Comments
F-ES Sitecore 5-Apr-18 7:36am    
Use the debugger to ensure the session variable has the data you think it does. Then view the page source to find your alert code and ensure it's as you expect. Use the console to see if there are any error messages. For example if any of your names have an apostrophe your code won't work.
helpwithmycode 5-Apr-18 8:02am    
oh yes, i do have 'enviroment.newline' next to each name. when i took it out, it worked! except now every name is mixed together as one giant mess. will have to figure out how to display each name as a new line. thanks so much for your help!
F-ES Sitecore 5-Apr-18 8:52am    
Use string.Split to split on the new line which will create an array of the names, then use string.Join to convert the array back to a string using something like a comma as a separator, so

John
Dave
Sue

will become

John, Dave, Sue
helpwithmycode 5-Apr-18 9:22am    
it works! thanks so much :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900