An object reference is required for nonstatic field, method....

Hello,

An newbie in C# trying to modify an existing source code. Any help will be greatly appreciated.

In form1.ascx.cs, it has...

namespace AC.Admin

{

using System;

using System.Data;

using System.Drawing;

using System.Web;

using System.Web.UI.WebControls;

using System.Web.UI.HtmlControls;

.

.

.

privatevoid SetGrid()

{

Int64 nORDER = Int64.Parse(Baps.PS["ORDER_NUM"]);

if (rblPay.SelectedValue=="Outorder")

{

decimal dTotalByMonth = DB1.SumByMonthO(nORDER,ddMonth.SelectedValue);

lbTotalByMonth.Text =string.Format("{0:c}",dTotalByMonth);

}

else

{

string xValue1=AGrid.GetSText(xABCValue);

}

In form2.ascx.cs, it has

publicstring GetSText(string xABCValue)

{

Control c2 =this.FindControl("eSearch");

TextBox ebSearch = (TextBox)c2;

return eSearch.Text;

I will get 'An object reference....' error with above codes, but if I have 'public static GetSText(string xABCValue),

then I would get 'keyword this is not valid'

Don't know how to reference the eSearch.Text value from from1

Thanks!!!!

[2671 byte] By [NancyH] at [2008-1-9]
# 1

Hi,

from your code i can see less one main problem,

you need crate instace of AGrid (new).

anycase the best way to member in control is by property

Code Snippet

public string SearchText

{

get { return this.ebSearch.Text; }

set { this.ebSearch.Text = value; }

}

Lior
lioris at 2007-10-3 > top of Msdn Tech,Feedback for forums and MSDN websites,Off-Topic Posts (Do Not Post Here)...
# 2

Thanks Lior, but where do I put the codes at, form1 or form2?

NancyH at 2007-10-3 > top of Msdn Tech,Feedback for forums and MSDN websites,Off-Topic Posts (Do Not Post Here)...
# 3
Where is the textbox --> form2

Lior

lioris at 2007-10-3 > top of Msdn Tech,Feedback for forums and MSDN websites,Off-Topic Posts (Do Not Post Here)...
# 4

HI

does the form2's name is the AGrid?

and you will invoke form2's method in the form1?

if i understood you wanted. i suggust you do following.

string xValue1=AGrid.GetSText(Control pControl,xABCValue);

}

In form2.ascx.cs, it has

public static string GetSText(Control pControl, string xABCValue)

{

Control c2 = pControl.FindControl("eSearch");

TextBox ebSearch = (TextBox)c2;

return eSearch.Text;

matt.

MattLin at 2007-10-3 > top of Msdn Tech,Feedback for forums and MSDN websites,Off-Topic Posts (Do Not Post Here)...
# 5

Thanks Matt and Lior,

AGrid is the form2. I copied the codes for Form2, it seems to compiled without error, however, Form1 gave me the following errors on string xValue1=AGrid.GetSText(Control pControl,xABCValue);

) expected

; expected

invalid expression term ','

What am I doing wrong, I have decleared string xABCValue = " "; but don't know how to declear Control pControl, is that the problem?

And Lior, to answer you question;

I'm not too sure where the textbox is at and the original programmer is not around for me to ask, the only codes I found that might give a clue in Form2 (AGrid) is as follow: What I need is when user enter a variable in the text box, let say '12345', from Form1, I need to be able to pick up '12345'

private void pbSearch_Click(object sender, EventArgs e)

{

Control c = this.FindControl("cbSearchCol");

Control c2 = this.FindControl("ebSearch");

if (c==null)

return;

if (c2==null)

return;

DropDownList cbSearchCol = (DropDownList)c;

TextBox ebSearch = (TextBox)c2;

ListItem li = cbSearchCol.SelectedItem;

string sLTrim = li.Attributes["ltrim"];

string sRaw = li.Attributes["raw"];

string sSearchType = li.Attributes["searchtype"];

Many Many thanks in advance!!!

NancyH at 2007-10-3 > top of Msdn Tech,Feedback for forums and MSDN websites,Off-Topic Posts (Do Not Post Here)...
# 6

Thanks for your post,but for ASP.NET questions, we have http://forums.asp.net, I recommend you post ASP.NET questions there for better reponses.

Zhi-XinYe-MSFT at 2007-10-3 > top of Msdn Tech,Feedback for forums and MSDN websites,Off-Topic Posts (Do Not Post Here)...