ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Return ArrayList to AJAX response and add embed object to play sound file in ASP.Net<p>Hi <a class="username" rel="mukesh1">mukesh1</a>,</p> <p>A WebMethod is called by AJAX. You can write JavaScript function to run after your AJAX call returns, but you can't call javascript inside your C#.</p> <p>Call the JavaScript function upon successful completion (callback) of the call to the WebMethod in your JS code.</p> <p>Check this example. Now please take its reference and correct your code.</p> <p><strong><span style="text-decoration: underline;">HTML</span></strong></p> <pre class="brush: html">&lt;script type=&#34;text/javascript&#34; src=&#34;https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js&#34;&gt;&lt;/script&gt; &lt;script type=&#34;text/javascript&#34; src=&#34;//cdn.jsdelivr.net/jquery/1/jquery.min.js&#34;&gt;&lt;/script&gt; &lt;link media=&#34;screen&#34; rel=&#34;stylesheet&#34; type=&#34;text/css&#34; href=&#34;//cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/css/toastr.css&#34; /&gt; &lt;script type=&#34;text/javascript&#34; src=&#34;https://cdnjs.cloudflare.com/ajax/libs/toastr.js/2.0.1/js/toastr.js&#34;&gt;&lt;/script&gt; &lt;script type=&#34;text/javascript&#34;&gt; function myFunction() { $.ajax({ type: &#34;POST&#34;, url: &#34;Default.aspx/getnotifications&#34;, data: &#39;&#39;, contentType: &#34;application/json; charset=utf-8&#34;, dataType: &#34;json&#34;, success: OnSuccess, failure: function (r) { } }); function OnSuccess(response) { $.each(response.d, function () { var text = this.Text; showpop(text, &#34;Lert&#34;); var obj = document.createElement(&#34;embed&#34;); obj.setAttribute(&#39;src&#39;, &#39;sms-alert-5-daniel_simon.wav&#39;); obj.setAttribute(&#39;id&#39;, &#39;beep&#39;); obj.setAttribute(&#39;width&#39;, &#39;0&#39;); obj.setAttribute(&#39;height&#39;, &#39;0&#39;); obj.setAttribute(&#39;enablejavascript&#39;, &#39;true&#39;); document.body.appendChild(obj); }) } } function showpop(msg) { toastr.info(msg); } $(function () { myFunction(); }); &lt;/script&gt;</pre> <p><strong><span style="text-decoration: underline;">C#</span></strong></p> <pre class="brush: csharp">[System.Web.Services.WebMethod] public static ArrayList getnotifications() { ArrayList list = new ArrayList(); DataTable dt = new DataTable(); dt.Columns.AddRange(new DataColumn[] { new DataColumn(&#34;client_id&#34;, typeof(int)), new DataColumn(&#34;name&#34;), new DataColumn(&#34;role&#34;), new DataColumn(&#34;company&#34;) }); dt.Rows.Add(1, &#34;John Hammond&#34;, &#34;Tester&#34;, &#34;Test 1&#34;); dt.Rows.Add(2, &#34;Mudassar Khan&#34;, &#34;MD&#34;, &#34;Test 2&#34;); dt.Rows.Add(3, &#34;Suzanne Mathews&#34;, &#34;Developer&#34;, &#34;Test 3&#34;); dt.Rows.Add(4, &#34;Robert Schidner&#34;, &#34;Engineer&#34;, &#34;Test 4&#34;); DataSet ds = new DataSet(); ds.Tables.Add(dt); for (int i = 0; i &lt; dt.Rows.Count; i++) { DataTable dt1 = new DataTable(); dt1.Columns.AddRange(new DataColumn[] { new DataColumn(&#34;clientid&#34;, typeof(int)) }); dt1.Rows.Add(1); dt1.Rows.Add(2); dt1.Rows.Add(5); dt1.Rows.Add(6); DataSet ds6 = new DataSet(); ds6.Tables.Add(dt1); for (int j = 0; j &lt; ds6.Tables[0].Rows.Count; j++) { if (ds.Tables[0].Rows[i][&#34;client_id&#34;].ToString() == ds6.Tables[0].Rows[j][&#34;clientid&#34;].ToString()) { string text1 = &#34;Candidate &#34; + ds.Tables[0].Rows[i][&#34;name&#34;].ToString() + &#34; interview for role &#34; + ds.Tables[0].Rows[i][&#34;role&#34;].ToString() + &#34; with company &#34; + ds.Tables[0].Rows[i][&#34;company&#34;].ToString() + &#34; is not confirmed &#34;; list.Add(new ListItem(text1)); } } } return list; }</pre> <p><strong><span style="text-decoration: underline;">Screenshot</span></strong></p> <p><img src="https://i.imgur.com/59n1fSm.jpg" alt="" width="359" height="243" /></p>https://www.aspforums.net:443/Threads/511692/Return-ArrayList-to-AJAX-response-and-add-embed-object-to-play-sound-file-in-ASPNet/https://www.aspforums.net:443/Threads/511692/Return-ArrayList-to-AJAX-response-and-add-embed-object-to-play-sound-file-in-ASPNet/Thu, 12 Jul 2018 06:01:19 GMT