473,396 Members | 2,033 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

user control issue

I have the following user control in my project simply
for setting focus to a control:
Public Class SetFocus

Inherits System.Web.UI.UserControl

Public Sub Focus(ByVal strClientID As String)

Dim script As String = ""

script = "<SCRIPT languange='JavaScript'>" & _

"document.getElementById('" & _

strClientID & "').focus();" & _

"</SCRIPT>"

Page.RegisterStartupScript("focus", script)

End Sub


I have the following code in my HTML section of the aspx
page that tries to access this user control:
<%@ Register TagPrefix="YTCIWebUserControls"
TagName="SetFocus" Src="../UserControls/SetFocus.ascx" %>

..

..

..

<YTCIWebUserControls:SetFocus id="SetFocus1"
runat="server"></YTCIWebUserControls:SetFocus>


I have the following code in my code-behind section of
the aspx page that tries to access this user control:
Protected ucFocus As New YTCIWebUserControls.SetFocus

..

..

..

If Not Page.IsPostBack Then

ucFocus.Focus(mtbFromDate.ClientID)

End If


When I try and run the page, I get the following error:
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the
execution of the current web request. Please review the
stack trace for more information about the error and
where it originated in the code.

Exception Details: System.NullReferenceException: Object
reference not set to an instance of an object.

Source Error:
Line 33: If Not Page.IsPostBack Then
Line 34: ucFocus.Focus(mtbFromDate.ClientID)

Source File:
C:\Inetpub\wwwroot\EmsAssist\Reports\MemberCall.as px.vb
Line: 34

Stack Trace:
[NullReferenceException: Object reference not set to an
instance of an object.]
YTCIWebUserControls.SetFocus.Focus(String strClientID)
EmsAssist.MemberCall.Page_Load(Object sender, EventArgs
e) in
C:\Inetpub\wwwroot\EmsAssist\Reports\MemberCall.as px.vb:35

System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Page.ProcessRequestMain() +731
However, when I don't use the user control, and implement
the code from the user control in place of using the user
control everything works fine as indicated below:
If Not Page.IsPostBack Then

Dim intRandomNbr As Integer

Dim script As String = ""

script = "<SCRIPT languange='JavaScript'>" & _

"document.getElementById('" & _

mtbFromDate.ClientID & "').focus();"
& _

"</SCRIPT>"

intRandomNbr = GenerateRandomNbr()

Page.RegisterStartupScript("focus" &
intRandomNbr, script)

End If


What am I doing wrong that the user control can't be
used???

Nov 18 '05 #1
2 2129
Ed
I believe you have to set the instance of ucFocus to
..FindControl("<your control name>"), then I believe it will work as
planned.
On Wed, 11 Aug 2004 16:56:04 -0700, "bill" <ws********@msn.com> wrote:
I have the following user control in my project simply
for setting focus to a control:
Public Class SetFocus

Inherits System.Web.UI.UserControl

Public Sub Focus(ByVal strClientID As String)

Dim script As String = ""

script = "<SCRIPT languange='JavaScript'>" & _

"document.getElementById('" & _

strClientID & "').focus();" & _

"</SCRIPT>"

Page.RegisterStartupScript("focus", script)

End Sub


I have the following code in my HTML section of the aspx
page that tries to access this user control:
<%@ Register TagPrefix="YTCIWebUserControls"
TagName="SetFocus" Src="../UserControls/SetFocus.ascx" %>

.

.

.

<YTCIWebUserControls:SetFocus id="SetFocus1"
runat="server"></YTCIWebUserControls:SetFocus>


I have the following code in my code-behind section of
the aspx page that tries to access this user control:
Protected ucFocus As New YTCIWebUserControls.SetFocus

.

.

.

If Not Page.IsPostBack Then

ucFocus.Focus(mtbFromDate.ClientID)

End If


When I try and run the page, I get the following error:
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the
execution of the current web request. Please review the
stack trace for more information about the error and
where it originated in the code.

Exception Details: System.NullReferenceException: Object
reference not set to an instance of an object.

Source Error:
Line 33: If Not Page.IsPostBack Then
Line 34: ucFocus.Focus(mtbFromDate.ClientID)

Source File:
C:\Inetpub\wwwroot\EmsAssist\Reports\MemberCall.a spx.vb
Line: 34

Stack Trace:
[NullReferenceException: Object reference not set to an
instance of an object.]
YTCIWebUserControls.SetFocus.Focus(String strClientID)
EmsAssist.MemberCall.Page_Load(Object sender, EventArgs
e) in
C:\Inetpub\wwwroot\EmsAssist\Reports\MemberCall.a spx.vb:35

System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Page.ProcessRequestMain() +731
However, when I don't use the user control, and implement
the code from the user control in place of using the user
control everything works fine as indicated below:
If Not Page.IsPostBack Then

Dim intRandomNbr As Integer

Dim script As String = ""

script = "<SCRIPT languange='JavaScript'>" & _

"document.getElementById('" & _

mtbFromDate.ClientID & "').focus();"
& _

"</SCRIPT>"

intRandomNbr = GenerateRandomNbr()

Page.RegisterStartupScript("focus" &
intRandomNbr, script)

End If


What am I doing wrong that the user control can't be
used???


Nov 18 '05 #2
Ed I don't know why this works but it does - I was having the same
problem and page.findcontrol("myusercontrolname") added to the
beginning of the subroutine where I was calling the property of the
user control from made my whole control spring to life :)
Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Ian | last post by:
I have a parent MDI with a menu that calls all the children forms and that works fine. My issue is I created a user control that looks like a toolbar and it has various windows controls on it and...
6
by: George Economos | last post by:
I am trying to display a user control contained within an c++ assembly in internet explorer. When I create an equivalent user control in c#, it displays just fine. Before I get into specifics,...
5
by: Drew | last post by:
I have a user control written in C#. This user control uses some of my mixed mode C++ libraries. My user control is currently residing on a .NET Windows Form. Everything works nicely. Now I am...
1
by: Shourie | last post by:
I've noticed that none of the child controls events are firing for the first time from the dynamic user control. Here is the event cycle. 1) MainPage_load 2) User control1_Load user clicks a...
6
by: Jim Heavey | last post by:
Hello, I have a user control which I place at the top of each page. I want to have code in this user control which sets the value of a couple of module variables and I was wondering if I create a...
1
by: Earl Teigrob | last post by:
Background: When I create a ASP.NET control (User or custom), it often requires security to be set for certain functionality with the control. For example, a news release user control that is...
3
by: c676228 | last post by:
Hi all, If I developed a phone user control which has requiredfieldvalidator, regularexpressionvalidator etc. The quesiton is if on a web form which have three phone fields and only any one of...
2
by: mikeingenito | last post by:
Hello, I have a a web form where i dynamically load a user control. The web page is an issue log, and each user control I add is a specific issue. I load them as follows: Try ...
9
by: timnels | last post by:
I have an issue where I have a user control that is launched into a floating form. At some point later, I allow the user to "unfloat" the user control by reparenting it on a split container in...
11
by: Brad Baker | last post by:
I'm building a small web application - I started out placing all my code in one file (config.aspx). As I continue to add code though it was becoming very unwieldy. After doing some searching...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.