473,382 Members | 1,400 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,382 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 2127
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.