Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Feb 27, 2012 02:05 AM by Dino He - MSFT
Member
10 Points
25 Posts
Feb 23, 2012 07:29 AM|LINK
How to call java script function from code behind having Update panel ? i want call javascript function from code behind using Vb.net.
i used ScriptManager1.RegisterStartupScript(Me, Me.GetType(), "alertUser", "printThis('p2');", True) but it does not work.
Please suggest me proper code or where i do wrong...
Thanks in advance.
Contributor
2268 Points
511 Posts
Feb 23, 2012 07:35 AM|LINK
Are you sure printThis('p2'); is working fine
I suggest you try it in the client side using onclick of a button for example, then you can determine where is the problem
Star
7756 Points
1626 Posts
Feb 23, 2012 07:41 AM|LINK
Hi,
try this
Page.RegisterStartupScript("alertUser", "alert('You must hit enter to continue');");
OR you can use this
ScriptManager.RegisterStartupScript(this, this.GetType(), "alertUser", "alert('You must hit enter to continue');", true);
also refer the link for detail
http://forums.asp.net/t/1391306.aspx/1
Feb 23, 2012 07:52 AM|LINK
Hi,i used this one also but it also not work. I am not getting where is the problem.
Feb 23, 2012 07:55 AM|LINK
hi,
I am sure printThis('p2'); works fine if it does not in update panel.
Actualy p2 is id of Div tag which Div i have to printed.
I can't call it on Onclientclick coz i have to do some insersation into database after that only i want print.
So this is problem i have.
8068 Points
1023 Posts
Microsoft
Feb 27, 2012 02:05 AM|LINK
Hi
Use ScriptManager.RegisterStartupScript method could call.
Here is the code:
HTML: <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script type="text/javascript"> function a() { alert("call function a"); } </script> </head> <body> <form id="form1" runat="server"> <div> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" /> </ContentTemplate> </asp:UpdatePanel> </div> </form> </body> </html> CS: public partial class WebForm3 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { ScriptManager.RegisterStartupScript(this, this.GetType(), "functiona", "a();", true); } }
amittarwade
Member
10 Points
25 Posts
How to call java script function from code behind having Update panel ?
Feb 23, 2012 07:29 AM|LINK
How to call java script function from code behind having Update panel ? i want call javascript function from code behind using Vb.net.
i used ScriptManager1.RegisterStartupScript(Me, Me.GetType(), "alertUser", "printThis('p2');", True) but it does not work.
Please suggest me proper code or where i do wrong...
Thanks in advance.
Muhammad Fak...
Contributor
2268 Points
511 Posts
Re: How to call java script function from code behind having Update panel ?
Feb 23, 2012 07:35 AM|LINK
Are you sure printThis('p2'); is working fine
I suggest you try it in the client side using onclick of a button for example, then you can determine where is the problem
If you feel it helps, Mark as answered so that it can help others to find solution.
For Any further questions, please contact me.
vinay13mar
Star
7756 Points
1626 Posts
Re: How to call java script function from code behind having Update panel ?
Feb 23, 2012 07:41 AM|LINK
Hi,
try this
Page.RegisterStartupScript("alertUser", "alert('You must hit enter to continue');");OR you can use this
ScriptManager.RegisterStartupScript(this, this.GetType(), "alertUser", "alert('You must hit enter to continue');", true);also refer the link for detail
http://forums.asp.net/t/1391306.aspx/1
V.K.Singh
amittarwade
Member
10 Points
25 Posts
Re: How to call java script function from code behind having Update panel ?
Feb 23, 2012 07:52 AM|LINK
Hi,i used this one also but it also not work. I am not getting where is the problem.
amittarwade
Member
10 Points
25 Posts
Re: How to call java script function from code behind having Update panel ?
Feb 23, 2012 07:55 AM|LINK
hi,
I am sure printThis('p2'); works fine if it does not in update panel.
Actualy p2 is id of Div tag which Div i have to printed.
I can't call it on Onclientclick coz i have to do some insersation into database after that only i want print.
So this is problem i have.
Dino He - MS...
Star
8068 Points
1023 Posts
Microsoft
Re: How to call java script function from code behind having Update panel ?
Feb 27, 2012 02:05 AM|LINK
Hi
Use ScriptManager.RegisterStartupScript method could call.
Here is the code:
HTML: <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script type="text/javascript"> function a() { alert("call function a"); } </script> </head> <body> <form id="form1" runat="server"> <div> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" /> </ContentTemplate> </asp:UpdatePanel> </div> </form> </body> </html> CS: public partial class WebForm3 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { ScriptManager.RegisterStartupScript(this, this.GetType(), "functiona", "a();", true); } }If you have any feedback about my replies, please contact msdnmg@microsoft.com
Microsoft One Code Framework