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]
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
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.
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!!!