Hello All--
I'm having a problem getting an onclick event to work. Here is my setup: I
have an external JavaScript file, a master page that registers the javascript
as an external file, and a content page that has controls that I am trying to
get onclick to work for.
// =====================
// MyScriptFile.js
// =====================
function ReportOnClick(msg)
{
alert('ReportOnClick: ' + msg);
}
// =====================
// MasterPage.master.cs
// =====================
protected void Page_Load(object sender, EventArgs e)
{
ClientScript.RegisterClientScriptInclude("MyJavaSc riptFile",
"MyScriptFile.js");
}
// =====================
// ContentPage.aspx.cs
// =====================
protected void Page_Load(object sender, EventArgs e)
{
if (! IsPostback)
{
// Does not work
Label1.Attributes.Add("onclick", "ReportOnClick('Label1 was
clicked.');");
// Does not work
// Label1.Attributes.Add("onclick",
"javascript:ReportOnClick('Label1 was clicked.');");
// Does work
// Label1.Attributes.Add("onclick", "alert('Label1 was clicked.');");
}
}
So, the adding of the attribute works fine, as I get an alert if I hardcode
one in. However, whenever I try to access a function in my external script,
I get a "Microsoft JScript runtime error: Object expected".
Any ideas?
Thanks,
PAGates 13 2363
"pagates" <pa*****@discussions.microsoft.comwrote in message
news:9A**********************************@microsof t.com...
Any ideas?
There was a similar problem discussed in another thread recently...
How are you including the JavaScript file in the MasterPage...?
"Mark Rae" wrote:
How are you including the JavaScript file in the MasterPage...?
// =====================
// MasterPage.master.cs
// =====================
protected void Page_Load(object sender, EventArgs e)
{
ClientScript.RegisterClientScriptInclude("MyJavaSc riptFile",
"MyScriptFile.js");
}
"pagates" <pa*****@discussions.microsoft.comwrote in message
news:D2**********************************@microsof t.com...
"Mark Rae" wrote:
>How are you including the JavaScript file in the MasterPage...?
// =====================
// MasterPage.master.cs
// =====================
protected void Page_Load(object sender, EventArgs e)
{
ClientScript.RegisterClientScriptInclude("MyJavaSc riptFile",
"MyScriptFile.js");
}
Hmm - yes, I think I see the problem...
Can you please do a View Source on the page and show the markup which the
above code has generated i.e. the "<include..." line in the header...
You're using the wrong format for the include. This format doesn't include a
file, but includes the code instead. The version you want takes three
parameters, not two. Check out the sample at: http://msdn2.microsoft.com/en-us/library/kx145dw2.aspx
--
Hope this helps,
Mark Fitzpatrick
Former Microsoft FrontPage MVP 199?-2006
"pagates" <pa*****@discussions.microsoft.comwrote in message
news:9A**********************************@microsof t.com...
Hello All--
I'm having a problem getting an onclick event to work. Here is my setup:
I
have an external JavaScript file, a master page that registers the
javascript
as an external file, and a content page that has controls that I am trying
to
get onclick to work for.
// =====================
// MyScriptFile.js
// =====================
function ReportOnClick(msg)
{
alert('ReportOnClick: ' + msg);
}
// =====================
// MasterPage.master.cs
// =====================
protected void Page_Load(object sender, EventArgs e)
{
ClientScript.RegisterClientScriptInclude("MyJavaSc riptFile",
"MyScriptFile.js");
}
// =====================
// ContentPage.aspx.cs
// =====================
protected void Page_Load(object sender, EventArgs e)
{
if (! IsPostback)
{
// Does not work
Label1.Attributes.Add("onclick", "ReportOnClick('Label1 was
clicked.');");
// Does not work
// Label1.Attributes.Add("onclick",
"javascript:ReportOnClick('Label1 was clicked.');");
// Does work
// Label1.Attributes.Add("onclick", "alert('Label1 was
clicked.');");
}
}
So, the adding of the attribute works fine, as I get an alert if I
hardcode
one in. However, whenever I try to access a function in my external
script,
I get a "Microsoft JScript runtime error: Object expected".
Any ideas?
Thanks,
PAGates
"Mark Rae" wrote:
"pagates" <pa*****@discussions.microsoft.comwrote in message
news:D2**********************************@microsof t.com...
"Mark Rae" wrote:
How are you including the JavaScript file in the MasterPage...?
// =====================
// MasterPage.master.cs
// =====================
protected void Page_Load(object sender, EventArgs e)
{
ClientScript.RegisterClientScriptInclude("MyJavaSc riptFile",
"MyScriptFile.js");
}
Hmm - yes, I think I see the problem...
Can you please do a View Source on the page and show the markup which the
above code has generated i.e. the "<include..." line in the header...
The following is in the body (not the header):
<script src="MyScriptFile.js" type="text/javascript"></script>
Note: there are other functions in that file that are called correctly, but
they are during the window.onload and window.onresize events, which are coded
into the javascript file. It seems to be a problem specifically with onclick.
Hi Mark,
Using either call for the function results in the same code in the body:
<script src="MyScript.js" type="text/javascript"></script>
Thanks,
PAGates
"Mark Fitzpatrick" wrote:
You're using the wrong format for the include. This format doesn't include a
file, but includes the code instead. The version you want takes three
parameters, not two. Check out the sample at: http://msdn2.microsoft.com/en-us/library/kx145dw2.aspx
--
Hope this helps,
Mark Fitzpatrick
Former Microsoft FrontPage MVP 199?-2006
"pagates" <pa*****@discussions.microsoft.comwrote in message
news:9A**********************************@microsof t.com...
Hello All--
I'm having a problem getting an onclick event to work. Here is my setup:
I
have an external JavaScript file, a master page that registers the
javascript
as an external file, and a content page that has controls that I am trying
to
get onclick to work for.
// =====================
// MyScriptFile.js
// =====================
function ReportOnClick(msg)
{
alert('ReportOnClick: ' + msg);
}
// =====================
// MasterPage.master.cs
// =====================
protected void Page_Load(object sender, EventArgs e)
{
ClientScript.RegisterClientScriptInclude("MyJavaSc riptFile",
"MyScriptFile.js");
}
// =====================
// ContentPage.aspx.cs
// =====================
protected void Page_Load(object sender, EventArgs e)
{
if (! IsPostback)
{
// Does not work
Label1.Attributes.Add("onclick", "ReportOnClick('Label1 was
clicked.');");
// Does not work
// Label1.Attributes.Add("onclick",
"javascript:ReportOnClick('Label1 was clicked.');");
// Does work
// Label1.Attributes.Add("onclick", "alert('Label1 was
clicked.');");
}
}
So, the adding of the attribute works fine, as I get an alert if I
hardcode
one in. However, whenever I try to access a function in my external
script,
I get a "Microsoft JScript runtime error: Object expected".
Any ideas?
Thanks,
PAGates
"pagates" <pa*****@discussions.microsoft.comwrote in message
news:50**********************************@microsof t.com...
>Can you please do a View Source on the page and show the markup which the above code has generated i.e. the "<include..." line in the header...
The following is in the body (not the header):
<script src="MyScriptFile.js" type="text/javascript"></script>
Indulge me...
1) Temporarily comment out the server-side code which adds the include file
2) Hard-code the above markup into the MasterPage, but with one tiny
modification:
<script src="MyScriptFile.js" type="text/javascript "></script>
Note the extra space at the end of "text/javascript "
Does it work now...?
"Mark Rae" wrote:
"pagates" <pa*****@discussions.microsoft.comwrote in message
news:50**********************************@microsof t.com...
Can you please do a View Source on the page and show the markup which the
above code has generated i.e. the "<include..." line in the header...
The following is in the body (not the header):
<script src="MyScriptFile.js" type="text/javascript"></script>
Indulge me...
1) Temporarily comment out the server-side code which adds the include file
2) Hard-code the above markup into the MasterPage, but with one tiny
modification:
<script src="MyScriptFile.js" type="text/javascript "></script>
Note the extra space at the end of "text/javascript "
Does it work now...?
No, but....
Hard-coding the markup (without the space) seems to allow it to work
correctly.
Or should that be spelled "correctly?!" So, it looks like there is a
problem somewhere in the mechanism with the RegisterClientSideInclude
function when specifying a javascript event with the same name as a
server-side event.
I'm not sure why I didn't think of trying that myself earlier, but I
didn't... Thank you!
Thanks again,
PAGates
"pagates" <pa*****@discussions.microsoft.comwrote in message
news:49**********************************@microsof t.com...
>Does it work now...?
No, but....
Damn! Scroll down to the thread entitled "menu controls on 2.0",
specifically the last few posts - I was hoping this might be the same
thing...
Hard-coding the markup (without the space) seems to allow it to work
correctly.
Hmm - there's "definitely" something not quite right with include files in
MasterPages...
I'm not sure why I didn't think of trying that myself earlier, but I
didn't... Thank you!
Welcome!
Wow. Damn is right! : )
I've done the Submit a Bug thing through the VS feedback. We'll see what
happens.
Thanks again for the help.
PAGates
"Mark Rae" wrote:
"pagates" <pa*****@discussions.microsoft.comwrote in message
news:49**********************************@microsof t.com...
Does it work now...?
No, but....
Damn! Scroll down to the thread entitled "menu controls on 2.0",
specifically the last few posts - I was hoping this might be the same
thing...
Hard-coding the markup (without the space) seems to allow it to work
correctly.
Hmm - there's "definitely" something not quite right with include files in
MasterPages...
I'm not sure why I didn't think of trying that myself earlier, but I
didn't... Thank you!
Welcome!
Wait a minute. I stand (un)corrected. I am still having the same problem
with the hard-coded page (although, by God, it did work once, for some
"random" reason).
PAGates
"pagates" wrote:
Wow. Damn is right! : )
I've done the Submit a Bug thing through the VS feedback. We'll see what
happens.
Thanks again for the help.
PAGates
"Mark Rae" wrote:
"pagates" <pa*****@discussions.microsoft.comwrote in message
news:49**********************************@microsof t.com...
>Does it work now...?
>
No, but....
Damn! Scroll down to the thread entitled "menu controls on 2.0",
specifically the last few posts - I was hoping this might be the same
thing...
Hard-coding the markup (without the space) seems to allow it to work
correctly.
Hmm - there's "definitely" something not quite right with include files in
MasterPages...
I'm not sure why I didn't think of trying that myself earlier, but I
didn't... Thank you!
Welcome!
"pagates" <pa*****@discussions.microsoft.comwrote in message
news:11**********************************@microsof t.com...
Wait a minute. I stand (un)corrected. I am still having the same problem
with the hard-coded page (although, by God, it did work once, for some
"random" reason).
There's clearly something wrong here - e,g, MasterPages won't even process a
self-closing <script /tag - has to be <script></script>
Well, at least it's "nice" to have confirmation from somebody else that it's
not just me...
"Mark Rae" wrote:
"pagates" <pa*****@discussions.microsoft.comwrote in message
news:11**********************************@microsof t.com...
Wait a minute. I stand (un)corrected. I am still having the same problem
with the hard-coded page (although, by God, it did work once, for some
"random" reason).
There's clearly something wrong here - e,g, MasterPages won't even process a
self-closing <script /tag - has to be <script></script> This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Spank |
last post by:
Hello,
I have a thumbnail image with the onclick event. When clicked, a
larger pic is displayed via a javascript funtion. When browsing the
page, the client does not realize the image is...
|
by: Curtis |
last post by:
Sorry if this is the wrong newsgroup in which to post.
We have an asp page on a webserver supporting asp pages.
How can we run/call a function on this page using an onclick or other event
from...
|
by: Galsaba |
last post by:
How can I send back an argumet with "onClick"?
<a href=test.php onClick="checkLink ('Gallon')" > 1 Gallon</a>
function checkLink(a)
{
return (a+3)
}
When the user click on the word "Gallon"...
|
by: José Carlos |
last post by:
Hi.
I am trying send a text value when click in an image.
If i write: onClick="javascript:document.client.submit();" send all form,
but i want to send only a input type text (name = cod),...
|
by: abs |
last post by:
My element:
<span onclick="alert('test')" id="mySpan">test</span>
Let's say that I don't know what is in this span's onclick event. Is it
possible to add another action to this element's onclick...
| |
by: usenet |
last post by:
See
<ul>
<li><a name="link1" onClick="alert(this.name);return false;"
href="#">Link1</a></li>
<li><a name="link2" href="javascript:alert(this);">Link2</a></li>
<li>Item 3</li>
</ul>
...
|
by: Fabrizio |
last post by:
Hi
I'm creating a web page where I use a rollover function on a html image. Can i associate the onclick event of this client control with a C# function resident on the aspx.cs file
Thank you...
|
by: Chris |
last post by:
I can create Javascript confirm message boxes during page creation, etc
adding them to the button attributes (many good posts on this!). But how can
I add this event after the button is pressed?
I...
|
by: Dave Mennenoh |
last post by:
I have a Flash based video player that uses a javaScript function on the
page to modify variables within the Flash. This is so, external, jpg,
thumbnails can change the video without reloading the...
|
by: Jl_G_0 |
last post by:
Hey all. hope someone can give me a little advice here.
I have a GridView, and on each line of it there's an
<asp:imagebuttonlike this:
<asp:ImageButton ID="hlCancel" runat="server"...
|
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,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
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...
|
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...
|
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: 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...
|
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...
| |
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
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 ...
| |