Need a few lines of code help, will pay!

R

Robert Johnson

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
 
R

Robert Johnson

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
 
N

Natty Gur

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 is TextBox)
{
MyDat oData = new MyDat(
((TextBox)Father.Controls).Text,((TextBox)Father.Controls).TabInde
x);
oT.Add(((TextBox)Father.Controls).ID,oData);
}
if (Father.Controls.Count > 0)
{
GetTextBoxes(Father.Controls,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
 
M

makthar

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.
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top