Showing posts with label public. Show all posts
Showing posts with label public. Show all posts

Monday, March 26, 2012

Access page viewstate from static method?

Does anyone know how to grab the current Session, or Viewstate from within a public static method? I've got some WebMethods and I'd like to get the page context once inside of the server-side method.

Thanks,
Mark

You can access the Session, but not the ViewState.

Inside a static method, you need to reference the Session like so: HttpContext.Current.Session


You can also pass EnableSession=true to the WebMethod attribute, but honestly I'd strongly recommend just sending the values up the pipe if at all possible (as params).

Saturday, March 24, 2012

about syntax error!

error: syntax error
source document :http://localhost/MyDream/AboutConten.asmx/js
line:3
source code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

my AboutConten.asmx is:

<%@dotnet.itags.org. WebService Language="C#" Class="MyDream1.AbouConten" %>

using System;
using System.Web;
using System.Data.SqlClient;
using System.Configuration;
using System.Web.Services;
using System.Web.Services.Protocols;
namespace MyDream1
{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class AbouConten : System.Web.Services.WebService
{

[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
[WebMethod]
public string ShowContent(string myId)
{
int id = Convert.ToInt32(myId);
string connStr = ConfigurationManager.AppSettings[0].ToString();
SqlConnection conn = new SqlConnection(connStr);
string cmdStr = "select this_content from myTopic where this_id = @dotnet.itags.org.this_id";
SqlCommand comm = new SqlCommand(cmdStr, conn);
comm.Parameters.AddWithValue("@dotnet.itags.org.this_id", id);
conn.Open();
SqlDataReader dr = comm.ExecuteReader();
dr.Read();
string returnStr = dr[0].ToString();
dr.Close();
conn.Close();
return returnStr;
}

}
}

why?

please help me!

thanks!

What do you see when you navigate to the proxy directly from the browser (typehttp://localhost/MyDream/AboutConten.asmx/js in your address bar)?