Wrox Programmer Forums
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 13th, 2006, 03:45 AM
Authorized User
 
Join Date: Jan 2006
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default class file

The below line set the text in the textbox inside the gridview

((TextBox)DtClass.FindMyControl(GridView,"TextBox1 ")).Text="hi";

Below is the code for finding the id of a control and doing an action with it,say finnding the textbox id inside a grid.


public static Control FindMyControl(Control c, string s)
        {
            Control found = null;

            for(int i = 0; i < c.Controls.Count; i++)
            {
                if(c.Controls[i].UniqueID.EndsWith(s)==true)
                {
                    found = c.Controls[i];
                    break;
                }
                else
                {
                    found = FindMyControl(c.Controls[i], s);
                    if(found != null)
                        break;
                }
            }
            return found;
        }

how do you convert the same code in vb.net.i did convert , but i am getting error of object reference not set to an instance of an object.
below is my vb code.

 Public Shared Function FindMyControl(ByVal c As Control, ByVal s As String) As Control
        Dim found As Control = Nothing
        Dim i As Integer = 0
        Do While (i < c.Controls.Count)
            If (c.Controls(i).UniqueID.EndsWith(s) = True) Then
                found = c.Controls(i)
                'TODO: Warning!!! break;If

            Else
                found = FindMyControl(c.Controls(i), s)
                If (Not (found) Is Nothing) Then
                    'TODO: Warning!!! break;If
                    GoTo p


                End If

            End If
            i = (i + 1)
        Loop
p:
        Return found
    End Function

Hope this is the right one.(Please tell me if any error is there above.im new to vb.net)

 CType(DtClass.FindMyControl(GridView1, "TextBox1"), TextBox).Text="hi"

while running the code im getting error object reference not sat to an instance of an object.








Similar Threads
Thread Thread Starter Forum Replies Last Post
Calling Class within ASPX file kingroon ASP.NET 2.0 Basics 3 July 9th, 2008 07:43 AM
Class File Asp_Developer Visual Basic 2005 Basics 1 April 30th, 2008 10:56 PM
Class file SKhna Ajax 1 February 4th, 2008 11:30 AM
Regarding Class Library (.dll) from class file manish.sharma04 BOOK: Wrox's ASP.NET 2.0 Visual Web Developer 2005 Express Edition Starter ISBN: 978-0-7645-8807-5 1 March 3rd, 2006 07:32 AM
class file server sivapmk J2EE 3 December 14th, 2003 08:02 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.