Getting variables from other controls & forms

Discussion in 'ASP .Net Building Controls' started by Rock, Sep 27, 2004.

  1. Rock

    Rock Guest

    How do I get a value of a textbox control from a form?

    On form1, I have a textbox with the value "CountyID" with a submit button;
    when the user clicks on Submit, it goes to Form2.

    How do I get the value of "countyID" (or whatever the user enters into the
    textbox) to display on form2?

    Something like request.Params("???"). request.Form????

    Request Two:
    If I put the forms into user controls, what would I do to get the
    information the user has selected? This is what I've tried:
    default.aspx has 2 controls: Ctrl1 and Ctrl2.
    Ctrl1 has a drop down list, say ddlCounty
    ddlCounty.SelectedItemChanged raises a public event
    SelectedItemChanged, with a ReadOnly property SelectedItem, which returns
    ddlCounty.SelectedItem
    Public ReadOnly Property SelectedItem() As
    ListItem

    Get

    Return ddlCounty.SelectedItem

    End Get

    End Property


    Ctrl2 on postback tries to read the selectedItem property
    from Ctrl1:
    Dim x As New ctrl1
    Response.Write(x.SelectedItem)


    When run, I get this error:

    Exception details: Object Reference Not Set to an instance of an object
    Source Error:

    Line 66: Public ReadOnly Property SelectedItem() As ListItem
    Line 67: Get
    Line 68: Return ddlCounty.SelectedItem
    Line 69: End Get
    Line 70: End Property



    Thanks.
     
    Rock, Sep 27, 2004
    #1
    1. Advertising

  2. Rock,

    Here's an attempt to answer your questions. Hope I'm understanding
    the problem correctly.

    First: In ASP.NET use Request.Params("[name of control]"). Classic
    ASP uses Request.Form("[name of control]"). For what it's worth,
    Request.Querystring() is the same in both.

    For the second request: If I'm not mistaken you need to add .Value to
    your SelectedItem property. Again this is fuzzy, but I think that
    SelectedItem is an object and SelectedItem.Value is just that (the
    value of the object).

    HTH,

    DB
     
    Danny Bloodworth, Oct 14, 2004
    #2
    1. Advertising

  3. hi
    Request.Params is a good idea. You can also use Page.FindControl("control
    ID"), and it must be executed in run time so you can use the following code
    in the CreateChildControls or render method

    if (!DesignMode)
    {
    TextBox TextBox1 =(TxtBox) Page.FindControl("ControlID");
    string text = TextBox1.Text;
    }

    I hope this can be helpful
    thank you
     
    Mohanad Haddadin, Oct 18, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. sagejoshua
    Replies:
    16
    Views:
    667
    Michael Winter
    Nov 9, 2005
  2. Andy B

    forms inside of other forms?

    Andy B, Jan 31, 2008, in forum: ASP .Net
    Replies:
    5
    Views:
    2,310
    Andy B
    Feb 1, 2008
  3. Replies:
    9
    Views:
    984
  4. Eric
    Replies:
    2
    Views:
    595
  5. Replies:
    9
    Views:
    133
    Brian McCauley
    May 12, 2006
Loading...

Share This Page