PASSING TEXT BOX VALUES FROM A USER CONTROL FILE TO ANOTHER CLASS FILE

lois waisbrooker

Total Post:70

Points:494
Posted by  lois waisbrooker
C#  ASP.Net 
 1041  View(s)
Ratings:
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.

  1. Kamlakar Singh

    Post:194

    Points:1396
    Re: Passing Text Box Values from a user control file to another class file

    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();

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!