Home > DeveloperSection > Forums > Passing Text Box Values from a user control file to another class file
lois waisbrooker
lois waisbrooker

Total Post:70

Points:494
Posted on    November-27-2014 10:35 PM

 ASP.Net C#  ASP.Net 
Ratings:


 1 Reply(s)
 604  View(s)
Rate this:

I am looking to pass values over from an ascx.cs user control file to another class file in my project. I need to be able to get the values of the dynamic text boxes from the user control to be able to put them in a database.

 

Here is what I have so far

 

User Control File

 

public void Page_Load(object sender, EventArgs e)

    {

        ItemBox.Text = Request.Form[ItemBox.UniqueID];

        NumberBox.Text = Request.Form[NumberBox.UniqueID];

        DescriptBox.Text = Request.Form[DescriptBox.UniqueID];

 

 

    }

Other class file

 

 ViewState[VIEWSTATEKEY] = int.Parse(ViewState[VIEWSTATEKEY].ToString()) + 1;

        LoadPageControls();

        RowID ++;

 

        string box1value = Request.Form[ItemBox.Text];

        string box2value = Request.Form[NumberBox.UniqueID];

        string box3value = Request.Form[DescriptBox.UniqueID];

 

        string sConnection = generic database address;

I have seen other people using a get method to pull the data over. But I can't get the syntax right and it keeps giving errors.

 

I tried this because I saw it here C# Get textBox value from another class and thought it would work, but with no joy

 

string box1value{ get {return ItemBox.Text;} }

There is most likely something simple that I am missing here but I have been stuck on this problem for a couple off weeks now and it is driving me up the walls trying to get this project finished so any help that you can give would be much appreciated.



Kamlakar Singh
Kamlakar Singh

Total Post:194

Points:1396
Posted on    November-28-2014 7:03 AM

User Control File

 

public void Page_Load(object sender, EventArgs e)

{

    Session["ItemBox"] = Request.Form[ItemBox.UniqueID];

    Session["NumberBox"] = Request.Form[NumberBox.UniqueID];

    Session["DescriptBox"] = Request.Form[DescriptBox.UniqueID];

}

Other class file

 

var ItemBox = (Session["ItemBox"] ?? "").ToString();

var NumberBox= (Session["NumberBox"] ?? "").ToString();

var DescriptBox= (Session["DescriptBox"] ?? "").ToString();


Don't want to miss updates? Please click the below button!

Follow MindStick