I have the following user control in my project simply
for setting focus to a control:
Public Class SetFocus
Inherits System.Web.UI.U serControl
Public Sub Focus(ByVal strClientID As String)
Dim script As String = ""
script = "<SCRIPT languange='Java Script'>" & _
"document.getEl ementById('" & _
strClientID & "').focus() ;" & _
"</SCRIPT>"
Page.RegisterSt artupScript("fo cus", 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="YTCI WebUserControls "
TagName="SetFoc us" Src="../UserControls/SetFocus.ascx" %>
..
..
..
<YTCIWebUserCon trols:SetFocus id="SetFocus1"
runat="server"> </YTCIWebUserCont rols: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 YTCIWebUserCont rols.SetFocus
..
..
..
If Not Page.IsPostBack Then
ucFocus.Focus(m tbFromDate.Clie ntID)
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.NullRefe renceException: Object
reference not set to an instance of an object.
Source Error:
Line 33: If Not Page.IsPostBack Then
Line 34: ucFocus.Focus(m tbFromDate.Clie ntID)
Source File:
C:\Inetpub\wwwr oot\EmsAssist\R eports\MemberCa ll.aspx.vb
Line: 34
Stack Trace:
[NullReferenceEx ception: Object reference not set to an
instance of an object.]
YTCIWebUserCont rols.SetFocus.F ocus(String strClientID)
EmsAssist.Membe rCall.Page_Load (Object sender, EventArgs
e) in
C:\Inetpub\wwwr oot\EmsAssist\R eports\MemberCa ll.aspx.vb:35
System.Web.UI.C ontrol.OnLoad(E ventArgs e) +67
System.Web.UI.C ontrol.LoadRecu rsive() +35
System.Web.UI.P age.ProcessRequ estMain() +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='Java Script'>" & _
"document.getEl ementById('" & _
mtbFromDate.Cli entID & "').focus() ;"
& _
"</SCRIPT>"
intRandomNbr = GenerateRandomN br()
Page.RegisterSt artupScript("fo cus" &
intRandomNbr, script)
End If
What am I doing wrong that the user control can't be
used??? 2 2148
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.U serControl Public Sub Focus(ByVal strClientID As String) Dim script As String = "" script = "<SCRIPT languange='Java Script'>" & _
"document.getEl ementById('" & _
strClientID & "').focus() ;" & _
"</SCRIPT>" Page.RegisterSt artupScript("fo cus", 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="YTCI WebUserControls " TagName="SetFo cus" Src="../UserControls/SetFocus.ascx" %>
.
.
.
<YTCIWebUserCo ntrols:SetFocus id="SetFocus1" runat="server" ></YTCIWebUserCont rols: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 YTCIWebUserCont rols.SetFocus
.
.
.
If Not Page.IsPostBack Then
ucFocus.Focus(m tbFromDate.Clie ntID)
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.NullRefe renceException: Object reference not set to an instance of an object.
Source Error:
Line 33: If Not Page.IsPostBack Then Line 34: ucFocus.Focus(m tbFromDate.Clie ntID)
Source File: C:\Inetpub\www root\EmsAssist\ Reports\MemberC all.aspx.vb Line: 34
Stack Trace:
[NullReferenceEx ception: Object reference not set to an instance of an object.] YTCIWebUserCon trols.SetFocus. Focus(String strClientID) EmsAssist.Memb erCall.Page_Loa d(Object sender, EventArgs e) in C:\Inetpub\www root\EmsAssist\ Reports\MemberC all.aspx.vb:35
System.Web.UI. Control.OnLoad( EventArgs e) +67 System.Web.UI. Control.LoadRec ursive() +35 System.Web.UI. Page.ProcessReq uestMain() +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='Java Script'>" & _
"document.getEl ementById('" & _
mtbFromDate.Cli entID & "').focus() ;" & _
"</SCRIPT>"
intRandomNbr = GenerateRandomN br()
Page.RegisterSt artupScript("fo cus" & intRandomNbr , script)
End If
What am I doing wrong that the user control can't be used???
Ed I don't know why this works but it does - I was having the same
problem and page.findcontro l("myusercontro lname") 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 :) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 it will be used by all of the
children forms. So I put the user control right underneath the menu control
on the parent. Anytime I call a child form it fills the parent area
including the area that the user control resides in. So I see the user...
|
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, is it possible to do the same with a c++ user
control or is this another example of c++ being a second class citizen in
..NET?
..NET 1.1
|
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 trying to use this control on a ASP
web page. I use the wizard (VS 2003) to create an ASP application and
drop my control onto the ASP page, I get :
"Operation cannot be completed"
|
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 dropdown in UC1
_________________________
1) MainPage_Load
2) User Control_1 Load
|
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 Variable name of "Public string Fred" in the control, will the page that uses the control be able to see this global variable or is there something that I need to do to make it available to the page which uses the control
Thanks in advance for your...
| |
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 comprised of a DataGrid may have separate permissions for adding, deleting and updating a news item.
Problem
Up until now, I have been implementing security directly inside the control. I will test directly against the security model to see if...
|
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 them is required, it seems in this case
user control is not good choice.
The only thing I can think of is eliminate the requiredfieldvalidator in
user control,
deal with required field in aspx page for the above case, am I right?
Any other ways?
|
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
sqlConn.Open()
|
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 another form.
Problem is if I wake a tooltip when the window is floated, and then try
the same thing when it is reparented, the app crashes with " Cannot
access a disposed object.Object name: 'Form'.
Presumably, this is a result of the tooltips...
|
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 online I found an article which suggested I might
place some of the code into web user controls. I created two new files
(general_info.ascx and store_front.ascx) and placed two chunks of code in
each.
I then registered the controls at the top of...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |