Reading control values and id within ASPX


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Reading control values and id within ASPX

  1. #1
    Greg Rothlander Guest

    Reading control values and id within ASPX


    I have a ASPX page with a simple ASP:Table that I build from my code behind.
    I'm building radiobuttons, textboxes, dropdownlist, etc... from my code
    behind and adding them to the ASP:Table. I am create the controls ID value
    based on the incoming XML.

    What I can not get to work is to create a way to read the controls and get
    the ID and text values back out once the user and entered values and submitted
    the page. I've tried the following without success:

    For each PageCtrl in Page.Controls
    If PageCtrl.ID = "Form1" Then
    For each FormCtrl in PageCtrl.Controls
    Dim strID = FormCtrl.ID
    Dim strText = FormCtrl.Text
    Next
    End If
    Next

    I've also added a loop to read through the asp:table's controls because I
    know the tables name. This isn't working.

    I need to read through the ASPX page and find the controls that I built into
    my table. I then need to read the ID and Text of each of them to send back
    to my Web Service.

    Once I get this I will need to read through the controls and find out the
    type of control before I create my reponse XML document.

    Any ideas or suggestions would be very much appreciated.

    Thanks for your time,
    Greg Rothlander



  2. #2
    Phil Guest

    Re: Reading control values and id within ASPX


    I have the same problem,

    the only way I can work-arround this is by keeping track of the given client-id's
    and then finding my data back in the Request.Form:

    mycontrol = Request.Form(myid)

    the problem is that as soon as you get the screen back, the controls don't
    exist anymore in the aspx server-side. It also depends where you create the
    controls (i guess that you should create them in the form.onload and nowhere
    else).

    it's amazing how difficult it is to get data back on the server that is visible
    in the browser. I needed something similar to be able to toggle between and
    editbox and a listbox, but the state (e.g. is it now an editbox) was destroyed
    everytime the page reloaded.)

    it's probably not the correct (intended) way to use asp.net...


  3. #3
    Greg Rothlander Guest

    Re: Reading control values and id within ASPX


    I just found your reply and it is very close to what I ended up doing. Thanks
    for getting back with me. Here is what I did, maybe this will help you in
    the future.

    I'm doing some really messed up stuff here. I built a completely dynamic
    form tool that uses a treeview control to drill down to the individual form.
    It pulls all of the forms definitions from the database and returns it via
    XML. So I do not known the name of the control, its type, if it's required,
    etc.... But I build all of this via the XML. When I submit the form the
    only thing I see that I can get any info out of is the forms collections
    or the page collection. The page collection was a pain to parse so used
    the form collection just like you are doing. I wrote the following code
    to do this for me.

    All in all I was very impressed that I actually got this thing built and
    that it works very well. I think I'll end up using this for all of my form
    type entry pages and as a reporting interface.

    For y = 0 To Request.Form.Count - 1
    If Left(strTemp, 1) <> "_" And strTemp And strTemp <> "submit.x" And strTemp
    <> "submit.y" Then

    'Find the RadioButtons and convert the ID to Yes/No
    If InStr(Request.Form.Item(y).ToString, "rdobtn", CompareMethod.Text)
    > 0 Then

    If InStr(Request.Form.Item(y).ToString, "Yes", CompareMethod.Text)
    > 0 Then

    strValue = "Yes"
    Else
    strValue = "No"
    End If
    Else
    strValue = Request.Form.Item(y).ToString
    End If

    'This just builds the XML document that will update the database
    AddReqParm(Request.Form.AllKeys.GetValue(y), strValue)
    End If
    Next

    "Phil" <paulgiverny@hotmail.com> wrote:
    >
    >I have the same problem,
    >
    >the only way I can work-arround this is by keeping track of the given client-id's
    >and then finding my data back in the Request.Form:
    >
    >mycontrol = Request.Form(myid)
    >
    >the problem is that as soon as you get the screen back, the controls don't
    >exist anymore in the aspx server-side. It also depends where you create

    the
    >controls (i guess that you should create them in the form.onload and nowhere
    >else).
    >
    >it's amazing how difficult it is to get data back on the server that is

    visible
    >in the browser. I needed something similar to be able to toggle between

    and
    >editbox and a listbox, but the state (e.g. is it now an editbox) was destroyed
    >everytime the page reloaded.)
    >
    >it's probably not the correct (intended) way to use asp.net...
    >



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center