[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 456
  • Last Modified:

global variable control passing from webForm to class file

Hi,

Is it possible to have a variable or a control that is declared in my webForm but I can call from my class file??

I want to be able to pass a value from WebForm1 to my class file.

Im using asp.net c#

any help as always greatly appreciated

J
0
jim_bob_jim
Asked:
jim_bob_jim
  • 5
  • 3
1 Solution
 
Gautham JanardhanCommented:
when u are creating the object of that class cant u just pass it in the constructor
0
 
jim_bob_jimAuthor Commented:
How would I do that??

For example I have a dropDownList control in my WebForm1

How would I pass in the SelectedValue of that DropDownList in my class file??

'" + DropDownList1.SelectedValue + "'   (within a select query in my class file)

Thanks
0
 
Gautham JanardhanCommented:
public class UrClass
{
public string Variable;
public UrClass(string FromWebForm)
{
  Variable = FromWebFOrm;
}
}]

// in the web form

UrClass Object = new UrClass(dropdownlist.SelectedValue.ToString());
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
jim_bob_jimAuthor Commented:
in my WebForm I have a number of controls that are dynamically driven from my database - WebForm1

I have a dataset that is populated from my class file - class.cs   As follows:

            DataSet ds = new DataSet();
            ds.ReadXmlSchema(@"C:DataSetSchema.xsd");

            OleDbDataAdapter da = new OleDbDataAdapter("select * from table1", myConn);
            da_wc.Fill(ds, DATATABLE_NAME);

I want the query in my class file to be filter the dataset based on the selections made from my WebForm.  I therefore need to be able to pass the values of my asp Controls in my WebForm up to my class.cs file so that the query and the dataset is filtered based on the user selections

            OleDbDataAdapter da = new OleDbDataAdapter("select * from table1 where col1 = '" + DropDownList.SelectedValue = "' and col2 = " + TextBox1.Text + "", myConn);

(where DropDownList1 & TextBox1 are declared and selected in WebForm1)

How can I do this??


            da_wc.Fill(ds, DATATABLE_NAME);
0
 
Gautham JanardhanCommented:
add a parameter to the class where this function is written
 DataSet ds = new DataSet();
            ds.ReadXmlSchema(@"C:DataSetSchema.xsd");

            OleDbDataAdapter da = new OleDbDataAdapter("select * from table1", myConn);
            da_wc.Fill(ds, DATATABLE_NAME);


like

public string Variable1;
public string Variable2;


public UrClass(string FromWebForm,string text)
{
  Variable1 = FromWebFOrm;
  Variable2 = text;
}

then change the change this
    OleDbDataAdapter da = new OleDbDataAdapter("select * from table1 where col1 = '" + DropDownList.SelectedValue = "' and col2 = " + TextBox1.Text + "", myConn);

as
    OleDbDataAdapter da = new OleDbDataAdapter("select * from table1 where col1 = '" + Variable1 += "' and col2 = " + Variable2 + "", myConn);
0
 
jim_bob_jimAuthor Commented:
Hi thanks for help so far

Im having trouble passing parameter into the class has the function is a DataSet method using the Get definition.

    public static DataSet myDataSet
    {
        get
        {
            OleDbConnection myConn = new OleDbConnection();
            myConn.ConnectionString = "xxx";

             DataSet ds = new DataSet();
            ds.ReadXmlSchema(@"C:DataSetSchema.xsd");

            OleDbDataAdapter da = new OleDbDataAdapter("select * from table1", myConn);
            da_wc.Fill(ds, DATATABLE_NAME);

            return ds;
        }
    }

How would I pass the values from WebForm1 into that function in my class as that does not allow me to pass them in using your method I dont think??

thanks for your help so far

J
0
 
Gautham JanardhanCommented:
can u post the constructor of his class where this function is
0
 
Gautham JanardhanCommented:
u wll have to convert this to a function
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now