【问题标题】:How to Use Session Like C# page to VB Page Using Page Methods如何使用 Session Like C# 页面到 VB 页面使用页面方法
【发布时间】:2015-01-06 14:38:19
【问题描述】:

运行两次或更多次后,它会给出像 Empty "" 这样的值或什么都没有。 怎么做? 我的第一页 aa.aspx 我做了 在 javascript 中

function InitializeRequest(path) {
// call server side method
PageMethods.SetDownloadPath(path);
}

背后的代码

[System.Web.Services.WebMethod]
public static string SetDownloadPath(string strpath)
{
Page objp = new Page();
objp.Session["strDwnPath"] = strpath; 
return strpath;
}

aspx 页面

<asp:ScriptManager EnablePageMethods="true" ID="MainSM" runat="server" ScriptMode="Release" LoadScriptsBeforeUI="true">

如何将 strpath 值转换为后面的 bb.aspx vb 代码???

【问题讨论】:

  • WebMethod中使用Session不需要创建Page对象

标签: javascript c# asp.net vb.net


【解决方案1】:

试试这个

[System.Web.Services.WebMethod]
public static string SetDownloadPath(string strpath)
{
        HttpContext.Current.Session["strDwnPath"] = strpath;
        return strpath;
}

【讨论】:

  • 如何在 vb 网页中获取该值?
  • 我在 bb.aspx 页面加载中使用了Dim SysNames = Session("strDwnPath").ToString(),但它会给出一个错误,例如 Object reference not set to an instance of an object.
  • @Suresh - upvote 答案将帮助其他人找到正确的解决方案。很高兴帮助你:)
  • 它不起作用..如果我第一次运行意味着它会给出正确的答案,否则它会出现错误并且 session("strDwnPath") 值什么都不是?我能做什么?
  • 您应该检查页面加载或其他事件中的某处。可能是您在其他事件中为您分配了null `session "strDwnPath"。
猜你喜欢
  • 2021-01-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-03-26
  • 2019-06-18
相关资源
最近更新 更多