473,385 Members | 1,521 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,385 software developers and data experts.

Execute JavaScript from server side

I have a HoverMenuExtender which contains an asp:PlaceHolder, this place
holder has a User Control and this control contrains a Button.

The problem I am having is after the button fires the click event I want to
do a server side function and then refresh the Page where the PlaceHolder
risides.
I have no problem doing the server side function, but the following 'alert'
never shows up after the server side funtion.

I am using the alert function instead of
'__doPostBack(document.getElementById('upRunningJo bs'), "test");' just for
testing as simplicity.

ScriptManager.RegisterStartupScript(this, GetType(), "Refresh",
"alert('test');", false);
Here's my button click event:

protected void butCancel_Click(object sender, EventArgs e)
{
RunningJobsController rjc = new RunningJobsController();
rjc.CancelJob(this.RReport.InstanceID);

//
// the alert from the following line never shows up
//
ScriptManager.RegisterStartupScript(this, GetType(), "Refresh",
"alert('test');", false);

}
Thank You.
Peter


Nov 13 '08 #1
7 4468
"Peter" <cz****@nospam.nospamwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
//
// the alert from the following line never shows up
//
ScriptManager.RegisterStartupScript(this, GetType(), "Refresh",
"alert('test');", false);
Does it work if you change the final argument from false to true...?
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Nov 14 '08 #2
No, it does not matter if it's true or false
"Mark Rae [MVP]" <ma**@markNOSPAMrae.netwrote in message
news:uq**************@TK2MSFTNGP05.phx.gbl...
"Peter" <cz****@nospam.nospamwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
>//
// the alert from the following line never shows up
//
ScriptManager.RegisterStartupScript(this, GetType(), "Refresh",
"alert('test');", false);

Does it work if you change the final argument from false to true...?
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Nov 14 '08 #3
"Peter" <cz****@nospam.nospamwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
>>//
// the alert from the following line never shows up
//
ScriptManager.RegisterStartupScript(this, GetType(), "Refresh",
"alert('test');", false);

Does it work if you change the final argument from false to true...?

No, it does not matter if it's true or false
If you do a View Source, do you see the JavaScript alert...?
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Nov 14 '08 #4
Hi Peter,

I think it should work if you set the last parameter to true. It looks very
strange. Could you send me a simple demo that can reproduce this problem?
I'll troubleshoot on my side to see what the problem is.

Regards,
Allen Chen
Microsoft Online Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subs...#notifications.

Note: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 2 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions. Issues of this
nature are best handled working with a dedicated Microsoft Support Engineer
by contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subs.../aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
| From: "Peter" <cz****@nospam.nospam>
| References: <#5**************@TK2MSFTNGP06.phx.gbl>
<uq**************@TK2MSFTNGP05.phx.gbl>
| Subject: Re: Execute JavaScript from server side
| Date: Thu, 13 Nov 2008 18:18:54 -0600
| Lines: 23
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.5512
| X-RFC2646: Format=Flowed; Response
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579
| Message-ID: <#U**************@TK2MSFTNGP05.phx.gbl>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: CPE-72-129-145-58.new.res.rr.com 72.129.145.58
| Path: TK2MSFTNGHUB02.phx.gbl!TK2MSFTNGP01.phx.gbl!TK2MSF TNGP05.phx.gbl
| Xref: TK2MSFTNGHUB02.phx.gbl
microsoft.public.dotnet.framework.aspnet:79845
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| No, it does not matter if it's true or false
|
|
| "Mark Rae [MVP]" <ma**@markNOSPAMrae.netwrote in message
| news:uq**************@TK2MSFTNGP05.phx.gbl...
| "Peter" <cz****@nospam.nospamwrote in message
| news:%2****************@TK2MSFTNGP06.phx.gbl...
| >
| >//
| >// the alert from the following line never shows up
| >//
| >ScriptManager.RegisterStartupScript(this, GetType(), "Refresh",
| >"alert('test');", false);
| >
| Does it work if you change the final argument from false to true...?
| >
| >
| --
| Mark Rae
| ASP.NET MVP
| http://www.markrae.net
|
|
|

Nov 14 '08 #5
"Mark Rae [MVP]" <ma**@markNOSPAMrae.netwrote in message
news:ul**************@TK2MSFTNGP03.phx.gbl...
"Peter" <cz****@nospam.nospamwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
>>>//
// the alert from the following line never shows up
//
ScriptManager.RegisterStartupScript(this, GetType(), "Refresh",
"alert('test');", false);

Does it work if you change the final argument from false to true...?

No, it does not matter if it's true or false

If you do a View Source, do you see the JavaScript alert...?
--
Mark Rae
ASP.NET MVP
http://www.markrae.net
No I do not

FYI: This is a DotNetNuke application.
Nov 14 '08 #6
Hi Peter,

Thanks for your code. It's a page life cycle issue. You're dynamically
creating controls in the ItemDataBound event handler so the click event of
the button will not fire on postback. To work it around please try
following steps:

1. Comment the following lines in the lstContent_ItemDataBound event
handler in the ViewRunningJobs.ascx.cs:
PopUpData pud
=(PopUpData)Page.LoadControl("~/DesktopModules/RunningJobs/PopUpData.ascx");
pud.RReport = (RunningReport)e.Item.DataItem;
phParameters.Controls.Add(pud);
phParameters.Visible = true;

2. Replace the DataList in ViewRunningJobs.ascx with following one:
<asp:DataList ID="lstContent" DataKeyField="ItemID" runat="server"
CellPadding="4"
OnItemDataBound="lstContent_ItemDataBound">
<ItemTemplate>
<table cellpadding="4" width="100%">
<tr>
<td valign="top" width="100%" align="left">
<asp:Image ID="imgJob" runat="server"
ImageUrl="" Height="36px" Width="42px" />
<asp:HyperLink ID="HyperLink1" NavigateUrl='<%#
EditUrl("ItemID",((int)DataBinder.Eval(Container.D ataItem,"ItemID")).ToStrin
g()) %>'
Visible="<%# IsEditable %>" runat="server">
<asp:Image ID="Image1" runat="server"
ImageUrl="~/images/edit.gif" AlternateText="Edit"
Visible="<%# IsEditable%>"
resourcekey="Edit" />
</asp:HyperLink>
<asp:Label ID="lblContent" Font-Size="12pt"
ForeColor="Blue" runat="server" />
--Start Time '<%#
DataBinder.Eval(Container.DataItem,"StartTime") %>' <span id="InstanceID"
style="display: none">Report ID '<%#
DataBinder.Eval(Container.DataItem, "InstanceID")%>'
</span>
<div>
<cc1:HoverMenuExtender
ID="HoverMenuExtender1" runat="server" TargetControlID="imgJob"
PopupControlID="pnlReportInfo"
PopupPosition="Right" PopDelay="25" OffsetY="-240" OffsetX="-30">
</cc1:HoverMenuExtender>
<asp:Panel ID="pnlReportInfo" runat="server"
CssClass="balloonstyle">
<br />
<br />
<asp:PlaceHolder ID="phParameters"
runat="server">
<uc1:PopUpData runat="server"
ID="PopUpData1" Visible="true" /></asp:PlaceHolder>
<DBWC:DynamicControlsPlaceholder
ID="phParameters1" runat="server">
</DBWC:DynamicControlsPlaceholder>
</asp:Panel>
</div>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>

In this way we add the PopUpData control in aspx directly instead of
dynamically creating it in the code behind. The control will then be
populated on an earlier stage of the page life cycle that can make sure the
event will fire on the postback.
Please let me know if it works.

Regards,
Allen Chen
Microsoft Online Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subs...#notifications.

Note: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 2 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions. Issues of this
nature are best handled working with a dedicated Microsoft Support Engineer
by contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subs.../aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
| From: "Peter" <cz****@nospam.nospam>
| References: <#5**************@TK2MSFTNGP06.phx.gbl>
<uq**************@TK2MSFTNGP05.phx.gbl>
| Subject: Re: Execute JavaScript from server side
| Date: Thu, 13 Nov 2008 18:18:54 -0600
| Lines: 23
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.5512
| X-RFC2646: Format=Flowed; Response
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579
| Message-ID: <#U**************@TK2MSFTNGP05.phx.gbl>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: CPE-72-129-145-58.new.res.rr.com 72.129.145.58
| Path: TK2MSFTNGHUB02.phx.gbl!TK2MSFTNGP01.phx.gbl!TK2MSF TNGP05.phx.gbl
| Xref: TK2MSFTNGHUB02.phx.gbl
microsoft.public.dotnet.framework.aspnet:79845
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| No, it does not matter if it's true or false
|
|
| "Mark Rae [MVP]" <ma**@markNOSPAMrae.netwrote in message
| news:uq**************@TK2MSFTNGP05.phx.gbl...
| "Peter" <cz****@nospam.nospamwrote in message
| news:%2****************@TK2MSFTNGP06.phx.gbl...
| >
| >//
| >// the alert from the following line never shows up
| >//
| >ScriptManager.RegisterStartupScript(this, GetType(), "Refresh",
| >"alert('test');", false);
| >
| Does it work if you change the final argument from false to true...?
| >
| >
| --
| Mark Rae
| ASP.NET MVP
| http://www.markrae.net
|
|
|

Nov 14 '08 #7
Thank You for your help

But the changes did not help, still JavaScript does not execut from the
button_click event in the User Control.
"Allen Chen [MSFT]" <v-******@online.microsoft.comwrote in message
news:bL**************@TK2MSFTNGHUB02.phx.gbl...
Hi Peter,

Thanks for your code. It's a page life cycle issue. You're dynamically
creating controls in the ItemDataBound event handler so the click event of
the button will not fire on postback. To work it around please try
following steps:

1. Comment the following lines in the lstContent_ItemDataBound event
handler in the ViewRunningJobs.ascx.cs:
PopUpData pud
=(PopUpData)Page.LoadControl("~/DesktopModules/RunningJobs/PopUpData.ascx");
pud.RReport = (RunningReport)e.Item.DataItem;
phParameters.Controls.Add(pud);
phParameters.Visible = true;

2. Replace the DataList in ViewRunningJobs.ascx with following one:
<asp:DataList ID="lstContent" DataKeyField="ItemID" runat="server"
CellPadding="4"
OnItemDataBound="lstContent_ItemDataBound">
<ItemTemplate>
<table cellpadding="4" width="100%">
<tr>
<td valign="top" width="100%" align="left">
<asp:Image ID="imgJob" runat="server"
ImageUrl="" Height="36px" Width="42px" />
<asp:HyperLink ID="HyperLink1" NavigateUrl='<%#
EditUrl("ItemID",((int)DataBinder.Eval(Container.D ataItem,"ItemID")).ToStrin
g()) %>'
Visible="<%# IsEditable %>" runat="server">
<asp:Image ID="Image1" runat="server"
ImageUrl="~/images/edit.gif" AlternateText="Edit"
Visible="<%# IsEditable%>"
resourcekey="Edit" />
</asp:HyperLink>
<asp:Label ID="lblContent" Font-Size="12pt"
ForeColor="Blue" runat="server" />
--Start Time '<%#
DataBinder.Eval(Container.DataItem,"StartTime") %>' <span id="InstanceID"
style="display: none">Report ID '<%#
DataBinder.Eval(Container.DataItem, "InstanceID")%>'
</span>
<div>
<cc1:HoverMenuExtender
ID="HoverMenuExtender1" runat="server" TargetControlID="imgJob"
PopupControlID="pnlReportInfo"
PopupPosition="Right" PopDelay="25" OffsetY="-240" OffsetX="-30">
</cc1:HoverMenuExtender>
<asp:Panel ID="pnlReportInfo"
runat="server"
CssClass="balloonstyle">
<br />
<br />
<asp:PlaceHolder ID="phParameters"
runat="server">
<uc1:PopUpData runat="server"
ID="PopUpData1" Visible="true" /></asp:PlaceHolder>
<DBWC:DynamicControlsPlaceholder
ID="phParameters1" runat="server">
</DBWC:DynamicControlsPlaceholder>
</asp:Panel>
</div>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>

In this way we add the PopUpData control in aspx directly instead of
dynamically creating it in the code behind. The control will then be
populated on an earlier stage of the page life cycle that can make sure
the
event will fire on the postback.
Please let me know if it works.

Regards,
Allen Chen
Microsoft Online Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subs...#notifications.

Note: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 2 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions. Issues of this
nature are best handled working with a dedicated Microsoft Support
Engineer
by contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subs.../aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.

--------------------
| From: "Peter" <cz****@nospam.nospam>
| References: <#5**************@TK2MSFTNGP06.phx.gbl>
<uq**************@TK2MSFTNGP05.phx.gbl>
| Subject: Re: Execute JavaScript from server side
| Date: Thu, 13 Nov 2008 18:18:54 -0600
| Lines: 23
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.5512
| X-RFC2646: Format=Flowed; Response
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579
| Message-ID: <#U**************@TK2MSFTNGP05.phx.gbl>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: CPE-72-129-145-58.new.res.rr.com 72.129.145.58
| Path: TK2MSFTNGHUB02.phx.gbl!TK2MSFTNGP01.phx.gbl!TK2MSF TNGP05.phx.gbl
| Xref: TK2MSFTNGHUB02.phx.gbl
microsoft.public.dotnet.framework.aspnet:79845
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| No, it does not matter if it's true or false
|
|
| "Mark Rae [MVP]" <ma**@markNOSPAMrae.netwrote in message
| news:uq**************@TK2MSFTNGP05.phx.gbl...
| "Peter" <cz****@nospam.nospamwrote in message
| news:%2****************@TK2MSFTNGP06.phx.gbl...
| >
| >//
| >// the alert from the following line never shows up
| >//
| >ScriptManager.RegisterStartupScript(this, GetType(), "Refresh",
| >"alert('test');", false);
| >
| Does it work if you change the final argument from false to true...?
| >
| >
| --
| Mark Rae
| ASP.NET MVP
| http://www.markrae.net
|
|
|

Nov 15 '08 #8

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

Similar topics

1
by: nerf | last post by:
How can I execute a javascript file(test.js) from within PHP. I'm running oscommerce and want to insert a menu created in javascript by Sothink DHTMLMenu. Thanks in advance
4
by: paul dallaire | last post by:
HI! I want to execute a link witch is in JavaScript, How do we execute this in asp server side if possible? Basically I don't want anyone to see this link in the code view. this is the link...
1
by: Michael SL | last post by:
Here is my problem. I have a delete record button. I want to prompt the user "Do you really want to delete?". If the user clicks 'OK' then I want to execute the CodeBehind on the server side to...
2
by: Dave | last post by:
Hi, I have a datagrid with a Templated column below. I want to execute some javascript before the postback to show a hidden "div" tag with static message of "Please Wait..." since the query takes...
4
by: Ian Kelly | last post by:
Hi All, I have an .net form that is split into two frames. The left frame has a tree that displays a list of all the customers. The right frame displays the appropriate clients information. ...
4
by: Mark Miller | last post by:
I've been trying to execute a javascript function just before submit on a form that contains an <input type="file"> input field and it isn't working. The reason I want to do this is the end users...
5
by: ezelasky | last post by:
I am trying to get a client side javascript function to invoke when the selection changes in a drop down list box. I have tried : ddl_specs.Attributes = "javascript"; ddl_specs.Attributes =...
31
by: Manfred Kooistra | last post by:
If I have a document like this: <html> <head> <script language=javascript> window.location.href='file.php'; </script> </head> <body> body content
3
by: Mel | last post by:
My server makes a url call that returns a whole bunch of javascripts. I will then have to execute them on the server. I stripped out everything between <bodyand </bodyand I can see the scripts. ...
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
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
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.