Showing posts with label method. Show all posts
Showing posts with label method. Show all posts

Saturday, March 24, 2012

passing variable value to method in .cs

I would like to set
errormessage and retrieve it in my method QWE()
It doesnt work. What am I doing wrong?

public class AppLogic
{
string errormessage ="We are sorry, DB Error try again later";

public static void QWE()
{
HttpContext.Current.Response.Write("<script type=text/javascript language=javascript>alert('" + errormessage +"');</script>");
}
}

Mate, How can we help you if you dont tell us what error message you get?

Try this though...

public string errormessage = errormessage ="We are sorry, DB Error try again later";


Embarrassed

CS0120: An object reference is required for the nonstatic field, method, or property 'AppLogic.errormessage'

public class AppLogic
{
publicstaticstring errormessage ="We are sorry, DB Error try again later";

public static void QWE()
{
HttpContext.Current.Response.Write("<script type=text/javascript language=javascript>alert('" +
AppLogic.errormessage +"');</script>");
}
}

static method can only manipulate static field.


lovely it works :)
thank you

Best to use getters and setters when passing information in vairable about your system.

//Delcare the variable as private.

#region Declerations

private

staticstring fromAddress =string.Empty;

#endregion

//Delcare the getters and setters as public

#region Properties

publicstaticstring FromAddress {get {return fromAddress; }set { fromAddress =value; } }

#endregion

passing variable value to method in .cs

I would like to set
errormessage and retrieve it in my method QWE()
It doesnt work. What am I doing wrong?

public class AppLogic{string errormessage ="We are sorry, DB Error try again later";public static void QWE() { HttpContext.Current.Response.Write("<script type=text/javascript language=javascript>alert('" + errormessage +"');</script>"); }}

Can you give an example of the return? What is the result/output of running this?


I would like to set
errormessage

string errormessage ="We are sorry, DB Error try again later";
and retrieve it in my method QWE()

('" + errormessage +"')
It doesnt work. What am I doing wrong?

public class AppLogic
{
string errormessage ="We are sorry, DB Error try again later";

public static void QWE()
{
HttpContext.Current.Response.Write("<script type=text/javascript language=javascript>alert('" + errormessage +"');</script>");
}

Passing variables between pages

What is the best method to pass variables between pages?
Is it through the Session object with large quantities of data and with the querystring/params with smaller quantities?

Hi smith,

Please have a look at this article.

http://msdn.microsoft.com/msdnmag/issues/03/04/ASPNETUserState/

For a quick reference,

http://msdn.microsoft.com/msdnmag/issues/03/04/ASPNETUserState/default.aspx?fig=true#fig1

HTH.


Yes, that is correct.

and for example when I assign a dataset to a Sessionobject as so:

Session("MyData")=MyDataSet
How can I retreive the data from this in another page? Do I need to create a new dataset object and assign the stored dataset to it, like so:
DataSetInOtherPage = Session("MyData") ?


Peter Smith wrote:

and for example when I assign a dataset to a Sessionobject as so:

Session("MyData")=MyDataSet
How can I retreive the data from this in another page? Do I need to create a new dataset object and assign the stored dataset to it, like so:
DataSetInOtherPage = Session("MyData") ?

Session stores its values as Objects, which means that it can store anything, as everything derives from Object. This means that you must cast the Session item when assigning it to a local variable. For example:

DataSet DataSetInOtherPage = Session["MyData"] as DataSet; [C#]

Dim DataSetInOtherPage As DataSet = CType(Session("MyData"), DataSet) [VB.NET]