Execute JavaScript from server side

P

Peter

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('upRunningJobs'), "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
 
A

Allen Chen [MSFT]

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:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#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/subscriptions/aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
| From: "Peter" <[email protected]>
| References: <#[email protected]>
<[email protected]>
| 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: <#[email protected]>
| 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!TK2MSFTNGP05.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
|
|
| | > | >
| >> //
| >> // 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
|
|
|
 
A

Allen Chen [MSFT]

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.DataItem,"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:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#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/subscriptions/aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
| From: "Peter" <[email protected]>
| References: <#[email protected]>
<[email protected]>
| 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: <#[email protected]>
| 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!TK2MSFTNGP05.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
|
|
| | > | >
| >> //
| >> // 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
|
|
|
 
P

Peter

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top