Need a few lines of code help, will pay!

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default Need a few lines of code help, will pay!

    I need to figure out how to go through all of the WebControls on a form,
    find all the ones that are named with a "txt" prefix (ie txtFirstName), and
    then retrieve the WebControl ID, Text (value), and Tab Index and put them
    into a collection or array.

    I have spent all day working on this and I just can't quite figure it out. I
    would appreciate any help you can give. I will happily pay $50 to the first
    person who can come up with a solution that works!!!

    Thanks a bunch!

    Robert Johnson



    Robert Johnson Guest

  2. Similar Questions and Discussions

    1. Extra Blank Lines in Code
      :frown; My wife uses Contribute 3 to do some edits and updates for a site that I use Dreamweaver 8 for. When I open a file in Dreamweaver that she...
    2. Blank Lines in program code
      After editing the Home page in Contribute 2 many blank lines are inserted into the page source code. The size of the page keeps increasing...
    3. Maximum Lines of Code
      :o All, I am having a peculiar problem with an <cfif> tag. I get an error message during the execution of the page that tells me the <cfif> tag...
    4. Why is there no error thrown in these 3 lines of code?
      $MyVar=1; if (MyVar ==1){ $var2="abc"; } Notice I left out the "$" in the IF statement. No error. It drops into the statement and sets the...
    5. Combine separate lines of code into one.
      Hi, I have some lingo that set an individual sprite height & width to 64. I need this to happen to 5 separte sprites. Currently my code is: ...
  3. #2

    Default Re: Need a few lines of code help, will pay!

    Unfortunately, that doesn't quite work. Tab Index is not a property of
    LiteralControl or ResourceBasedLiteralControl. As a result, I get the
    following error: Public member 'TabIndex' on type
    'ResourceBasedLiteralControl' not found.

    It needs to use the WebControl instead of Control.

    I am still still looking for a solution and am happy to pay for it! If you
    (or anyone else) has a fix, I really need one!

    Thanks,

    Robert



    "John Knoop" <john.k@home.se> wrote in message
    news:Oxe5WMWWDHA.216@TK2MSFTNGP11.phx.gbl...
    > Wouldn't something like this work?
    >
    > Dim x as object
    >
    > For each x in page.controls
    > if left(x.id, 3) = "txt" then
    > 'do something with x.text
    > end if
    > next x
    >
    > /john
    >
    > "Robert Johnson" <buttons@internetwebzone.com> wrote in message
    > news:eb9t#WVWDHA.608@TK2MSFTNGP12.phx.gbl...
    > > I need to figure out how to go through all of the WebControls on a form,
    > > find all the ones that are named with a "txt" prefix (ie txtFirstName),
    > and
    > > then retrieve the WebControl ID, Text (value), and Tab Index and put
    them
    > > into a collection or array.
    > >
    > > I have spent all day working on this and I just can't quite figure it
    out.
    > I
    > > would appreciate any help you can give. I will happily pay $50 to the
    > first
    > > person who can come up with a solution that works!!!
    > >
    > > Thanks a bunch!
    > >
    > > Robert Johnson
    > >
    > >
    > >
    >
    >

    Robert Johnson Guest

  4. #3

    Default Re: Need a few lines of code help, will pay!


    Hi,

    Here the code. I prefer to use types then text. Keep the mony ... :-)

    1) Class to hold data :
    class MyDat
    {
    public string Text;
    public int TabIndex;
    public MyDat(string inText,int inTabIndex)
    {
    Text = inText;
    TabIndex = inTabIndex;
    }
    }

    2) Form Load :
    private void Page_Load(object sender, System.EventArgs e)
    {

    // Put user code to initialize the page here
    System.Collections.Hashtable oT = new
    System.Collections.Hashtable();
    HtmlForm theForm = (HtmlForm)this.FindControl("WebForm3");
    GetTextBoxes(theForm,oT);

    }

    3) recursiv function :
    private void GetTextBoxes(Control Father,System.Collections.Hashtable
    oT)
    {
    for (int i = 0 ; i< Father.Controls.Count; i++)
    {
    if (Father.Controls[i] is TextBox)
    {
    MyDat oData = new MyDat(
    ((TextBox)Father.Controls[i]).Text,((TextBox)Father.Controls[i]).TabInde
    x);
    oT.Add(((TextBox)Father.Controls[i]).ID,oData);
    }
    if (Father.Controls.Count > 0)
    {
    GetTextBoxes(Father.Controls[i],oT);
    }
    }
    }

    Natty Gur, CTO
    Dao2Com Ltd.
    34th Elkalay st. Raanana
    Israel , 43000
    Phone Numbers:
    Office: +972-(0)9-7740261
    Fax: +972-(0)9-7740261
    Mobile: +972-(0)58-888377


    *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    Don't just participate in USENET...get rewarded for it!
    Natty Gur Guest

  5. #4

    Default Need a few lines of code help, will pay!

    You have to check for the type of the control.
    Here's a snippet that help. You will have to refine it
    depending on what you are trying to do.

    Dim ctl As Control
    Dim ctlname As String
    Dim tb As TextBox
    Dim tbvalue As String

    For Each ctl In Page.FindControl
    ("form1").Controls
    ctlname = ctl.ID
    'At this point you can also check if name starts with txt
    If Ctl.GetType.ToString=
    "System.Web.UI.WebControls.TextBox" Then
    tb = ctl
    tb.TabIndex = 1 'or whatever
    tbvalue = tb.Text
    End If
    Next

    Ofcourse if you put this code in the page_load section
    the value of the text box will be nothing.
    >-----Original Message-----
    >I need to figure out how to go through all of the
    WebControls on a form,
    >find all the ones that are named with a "txt" prefix (ie
    txtFirstName), and
    >then retrieve the WebControl ID, Text (value), and Tab
    Index and put them
    >into a collection or array.
    >
    >I have spent all day working on this and I just can't
    quite figure it out. I
    >would appreciate any help you can give. I will happily
    pay $50 to the first
    >person who can come up with a solution that works!!!
    >
    >Thanks a bunch!
    >
    >Robert Johnson
    >
    >
    >
    >.
    >
    makthar Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139