ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2017 www.aspforums.com. All rights reserved.How to access WebMethod Session value in another page using jQuery Ajax in ASP.NetHi @mohdImran,<br />Please try the following<br /><br /><a href = 'link(Threads/158537/Send-DropDownList-Selected-Item-Value-to-another-Page-using-Session-in-ASPNet/)'>Send DropDownList Selected Item Value to another Page using Session in ASP.Net</a><br /><br />It might help you.<br /><br />Cheers Andrea.http://www.aspforums.net/Threads/618168/How-to-access-WebMethod-Session-value-in-another-page-using-jQuery-Ajax-in-ASPNet/http://www.aspforums.net/Threads/618168/How-to-access-WebMethod-Session-value-in-another-page-using-jQuery-Ajax-in-ASPNet/Sun, 18 Dec 2016 23:32:33 GMTHow to access WebMethod Session value in another page using jQuery Ajax in ASP.Net<p>Hi <a class="username" rel="mohdImran">mohdImran</a>,</p> <p>as per your explaination i have cross checked with code and its working fine and please let me know what exactly you are trying to do?</p>http://www.aspforums.net/Threads/618168/How-to-access-WebMethod-Session-value-in-another-page-using-jQuery-Ajax-in-ASPNet/http://www.aspforums.net/Threads/618168/How-to-access-WebMethod-Session-value-in-another-page-using-jQuery-Ajax-in-ASPNet/Mon, 19 Dec 2016 03:54:05 GMTHow to access WebMethod Session value in another page using jQuery Ajax in ASP.Net<p>&nbsp;This is my html coding where i am calling webmethod using jquery</p> <pre class="brush: html">&lt;%@ Page Language=&#34;C#&#34; AutoEventWireup=&#34;true&#34; CodeBehind=&#34;database_reg.aspx.cs&#34; Inherits=&#34;fleet.ajax.database_reg&#34; %&gt; &lt;div class=&#34;row&#34;&gt; &lt;div id=&#34;dialog&#34; style=&#34;background-color: aliceblue;&#34;&gt; &lt;input id=&#34;txt_db_name&#34; type=&#34;text&#34; runat=&#34;server&#34; /&gt; &lt;label id=&#34;lbl_db&#34; runat=&#34;server&#34;&gt; &lt;/label&gt; &lt;/div&gt; &lt;/div&gt; &lt;style&gt; .ui-dialog-titlebar-close { visibility: hidden; } &lt;/style&gt; &lt;script type=&#34;text/javascript&#34;&gt; $(document).ready(function (){ var dialogDiv = $(&#39;#dialog&#39;); dialogDiv.dialog({ title: &#39;Please Enter Database Name&#39;, draggable: false, resizable: false, closeOnEscape: false, model: true, autoOpen: true, buttons: { &#39;Submit&#39;: createdb, //&#39;Cancel&#39;: function () { // dialogDiv.dialog(&#39;close&#39;); // clearInputFields(); //} } }); function createdb() { //debugger var dbname = $(&#39;#txt_db_name&#39;).val(); $.ajax({ url: &#39;ajax/database_reg.aspx/createdb&#39;, method: &#39;post&#39;, data: &#34;{ dbname: &#39;&#34; + dbname + &#34;&#39;}&#34;, contentType: &#39;application/json; charset=utf-8&#39;, dataType: &#39;json&#39;, success: function () { } }); } }); &lt;/script&gt;</pre> <p>and this is my code behind where web method is definde and session also but problem is that i am unable to get session to another page.</p> <pre class="brush: csharp">using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.IO; using System.Linq; using System.Web; using System.Web.Services; using Microsoft.SqlServer.Management.Common; using Microsoft.SqlServer.Management.Smo; using System.Xml; namespace fleet.ajax { public partial class database_reg : System.Web.UI.Page { [WebMethod(EnableSession = true)] public static void createdb(string dbname) { String str; SqlConnection myConn = new SqlConnection(&#34;Data Source=xx.xx.xx.xx;Initial Catalog=master;User ID=sa;Password=xxxxx;&#34;); str = &#34;CREATE DATABASE &#34; + dbname + &#34; ON PRIMARY &#34; + &#34;(NAME = N&#39;&#34; + dbname + &#34;&#39;, &#34; + &#34;FILENAME = N&#39;C:\\Program Files\\Microsoft SQL Server\\MSSQL10_50.MSSQLSERVER\\MSSQL\\DATA\\&#34; + dbname + &#34;.mdf&#39;, &#34; + &#34;SIZE = 5MB, MAXSIZE = 10MB, FILEGROWTH = 10%) &#34; + &#34;LOG ON (NAME = N&#39;&#34; + dbname + &#34;_log&#39;, &#34; + &#34;FILENAME = N&#39;C:\\Program Files\\Microsoft SQL Server\\MSSQL10_50.MSSQLSERVER\\MSSQL\\DATA\\&#34; + dbname + &#34;_log.ldf&#39;, &#34; + &#34;SIZE = 1MB, &#34; + &#34;MAXSIZE = 5MB, &#34; + &#34;FILEGROWTH = 10%)&#34;; SqlCommand myCommand = new SqlCommand(str, myConn); try { HttpContext.Current.Session[&#34;database&#34;] = dbname; myConn.Open(); myCommand.ExecuteNonQuery(); SqlConnection myConn1 = new SqlConnection(&#34;Data Source=xx.xx.xx.xx;Initial Catalog=&#34; + dbname + &#34;;User ID=sa;Password=xxxxxx;&#34;); myConn1.Open(); FileInfo file = new FileInfo(System.Web.HttpContext.Current.Server.MapPath(&#34;script.sql&#34;)); string strscript = file.OpenText().ReadToEnd(); string strupdatescript = strscript.Replace(&#34;[demo]&#34;, dbname); Server server = new Server(new ServerConnection(myConn1)); server.ConnectionContext.ExecuteNonQuery(strupdatescript); myConn1.Close(); } catch (System.Exception ex) { // MessageBox.Show(ex.ToString(), &#34;MyProgram&#34;, MessageBoxButtons.OK, MessageBoxIcon.Information); } finally { if (myConn.State == ConnectionState.Open) { myConn.Close(); } } bool isNew = false; string path = System.Web.HttpContext.Current.Server.MapPath(&#34;~/Web.Config&#34;); XmlDocument doc = new XmlDocument(); doc.Load(path); XmlNodeList list = doc.DocumentElement.SelectNodes(string.Format(&#34;connectionStrings/add[@name=&#39;{0}&#39;]&#34;, dbname)); XmlNode node; isNew = list.Count == 0; if (isNew) { node = doc.CreateNode(XmlNodeType.Element, &#34;add&#34;, null); XmlAttribute attribute = doc.CreateAttribute(&#34;name&#34;); attribute.Value = dbname; node.Attributes.Append(attribute); attribute = doc.CreateAttribute(&#34;connectionString&#34;); attribute.Value = &#34;&#34;; node.Attributes.Append(attribute); } else { node = list[0]; } string conString = node.Attributes[&#34;connectionString&#34;].Value; SqlConnectionStringBuilder conStringBuilder = new SqlConnectionStringBuilder(conString); conStringBuilder.InitialCatalog = dbname; conStringBuilder.DataSource = &#34;xx.xx.xx.xx&#34;; conStringBuilder.UserID = &#34;sa&#34;; conStringBuilder.Password = &#34;mxxxx&#34;; node.Attributes[&#34;connectionString&#34;].Value = conStringBuilder.ConnectionString; if (isNew) { doc.DocumentElement.SelectNodes(&#34;connectionStrings&#34;)[0].AppendChild(node); } doc.Save(path); } protected void Page_Load(object sender, EventArgs e) { } } } </pre> <p>&nbsp;</p>http://www.aspforums.net/Threads/618168/How-to-access-WebMethod-Session-value-in-another-page-using-jQuery-Ajax-in-ASPNet/http://www.aspforums.net/Threads/618168/How-to-access-WebMethod-Session-value-in-another-page-using-jQuery-Ajax-in-ASPNet/Mon, 19 Dec 2016 05:07:35 GMTHow to access WebMethod Session value in another page using jQuery Ajax in ASP.Net<p>Hi <a class="username" rel="mohdImran"> mohdImran</a>,</p> <p>I have a created a sample which full fill your requirement.</p> <p>You need to modify according to your requirement.</p> <p><span style="text-decoration: underline;">Default.aspx</span></p> <pre class="brush: html">&lt;div id=&#34;dialog&#34; style=&#34;background-color: aliceblue;&#34;&gt; &lt;input id=&#34;txt_db_name&#34; type=&#34;text&#34; runat=&#34;server&#34; /&gt; &lt;label id=&#34;lbl_db&#34; runat=&#34;server&#34;&gt; &lt;/label&gt; &lt;/div&gt; &lt;div&gt; &lt;style&gt; .ui-dialog-titlebar-close { visibility: hidden; } &lt;/style&gt; &lt;script type=&#34;text/javascript&#34; src=&#34;http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js&#34;&gt;&lt;/script&gt; &lt;script src=&#34;http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.9/jquery-ui.js&#34; type=&#34;text/javascript&#34;&gt;&lt;/script&gt; &lt;link href=&#34;http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.9/themes/blitzer/jquery-ui.css&#34; rel=&#34;stylesheet&#34; type=&#34;text/css&#34; /&gt; &lt;script type=&#34;text/javascript&#34;&gt; $(document).ready(function () { var dialogDiv = $(&#39;#dialog&#39;); dialogDiv.dialog({ title: &#39;Please Enter Database Name&#39;, draggable: false, resizable: false, closeOnEscape: false, model: true, autoOpen: true, buttons: { &#39;Submit&#39;: createdb } }); }); function createdb() { var dbname = $(&#39;#txt_db_name&#39;).val(); $.ajax({ url: &#39;Default.aspx/createdb&#39;, type: &#39;POST&#39;, data: &#34;{dbname: &#39;&#34; + dbname + &#34;&#39;}&#34;, contentType: &#39;application/json; charset=utf-8&#39;, dataType: &#39;json&#39;, success: function () { window.location.href = &#39;Default2.aspx&#39;; } }); } &lt;/script&gt; &lt;/div&gt;</pre> <p><span style="text-decoration: underline;">Default.aspx.cs</span></p> <pre class="brush: csharp">[WebMethod(EnableSession = true)] public static void createdb(string dbname) { HttpContext.Current.Session[&#34;database&#34;] = dbname; }</pre> <p><span style="text-decoration: underline;">Default2.aspx</span></p> <pre class="brush: html">&lt;div&gt; &lt;asp:Label ID=&#34;lblSessionData&#34; runat=&#34;server&#34; /&gt; &lt;/div&gt;</pre> <p><span style="text-decoration: underline;">Default2.aspx.cs</span></p> <pre class="brush: csharp">protected void Page_Load(object sender, EventArgs e) { if (!string.IsNullOrEmpty(Session[&#34;database&#34;].ToString())) { lblSessionData.Text = Session[&#34;database&#34;].ToString(); } else { lblSessionData.Text = &#34;Empty Session Data.&#34;; } }</pre> <p><span style="text-decoration: underline;">ScreenShot</span></p> <p><span style="text-decoration: underline;"><img src="http://i988.photobucket.com/albums/af3/mudassarkhan/618168.gif" alt="" width="366" height="453" /></span></p>http://www.aspforums.net/Threads/618168/How-to-access-WebMethod-Session-value-in-another-page-using-jQuery-Ajax-in-ASPNet/http://www.aspforums.net/Threads/618168/How-to-access-WebMethod-Session-value-in-another-page-using-jQuery-Ajax-in-ASPNet/Tue, 20 Dec 2016 07:10:42 GMT