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
    Public ReadOnly Property SelectedItem() As


    Return ddlCounty.SelectedItem

    End Get

    End Property

    Ctrl2 on postback tries to read the selectedItem property
    from Ctrl1:
    Dim x As New ctrl1

    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

    Rock, Sep 27, 2004
    1. Advertisements

  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).


    Danny Bloodworth, Oct 14, 2004
    1. Advertisements

  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
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Similar Threads
There are no similar threads yet.