Hi all !
I've unsuccesfully tried to display an alertbox in Javascript when pushing a button. When the event is fired I inject JS code in a literal by codebehind. That works fine as long as my button is not in an UpdatePanel.
In the .aspx :
<asp:ScriptManager EnablePartialRendering="true" ID="AtlasSM" runat="server" /> <asp:UpdatePanel ID="AtlasUpdate1" runat="server" UpdateMode="Conditional"> <ContentTemplate> <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" /> <asp:Literal ID="Literal1" runat="server" EnableViewState="False" Mode="Transform"></asp:Literal> </ContentTemplate> <Triggers> <asp:AsyncPostbackTrigger ControlID="Button1" EventName="Click" /> </Triggers> </asp:UpdatePanel>In the .cs :
protected void Button1_Click(object sender, EventArgs e) { LiteralOpenFax.Text ="<SCRIPT language='javascript' type='text/javascript'>alert('test');</SCRIPT>"; }
Any suggestions? Thanks!
Dindin:
LiteralOpenFax.Text ="<SCRIPT language='javascript' type='text/javascript'>alert('test');</SCRIPT>";
Oops, it's Literal1.Text ="<SCRIPT language='javascript' type='text/javascript'>alert('test');</SCRIPT>";, not LiteralOpenFax ;)
But doesn't work anymore
Hi,
you should use the RegisterClientScript or RegisterStartupScript methods of the ScriptManager control to inject Javascript in the page during a partial postback.
Hi Garbin, thank you for reply!
Yes, I've used RegisterClientScriptBlock, but that's dont work in a postback.
protected void Page_Load(object sender, System.EventArgs e){if ( ! Page.IsPostBack )Page.RegisterClientScriptBlock("ScriptNotPostBack","<SCRIPT>alert('My script in page load : good');</SCRIPT>");elsePage.RegisterClientScriptBlock("ScriptInPostBack","<SCRIPT>alert('My script after a postback : that does not work');</SCRIPT>");}
Is my code bad?
Like Garbin said, you want RegisterClientScriptBlock on theScriptManagerobject.
So change those to calls to ScriptManager.RegisterClientScriptBlock().
Ok, greate !
Thank you guys
No comments:
Post a Comment