Connecting Tech Pros Worldwide Forums | Help | Site Map

ASP.NET C# Calling a javascript function from asp

chathura86's Avatar
Member
 
Join Date: May 2007
Location: Homagama, Sri Lanka
Posts: 92
#1: Aug 29 '08
i am creating a ajax enabled page

i have a update panel and inside that i have a button

what i want to do is when the button clicked it will do some
process and after that i want to show the result in a message box

i want to know how to call the javascript alert() function;

for a example

client code:
Expand|Select|Wrap|Line Numbers
  1. <asp:UpdatePanel ID="updatePnl" runat="server">
  2.       ....................
  3.       .....................
  4.         <asp:Button ID="Button1" Text="Login" OnClick="Button1_Click" runat="server" />
  5.       .......................
  6.       ........................
  7. </asp:UpdatePanel>
  8.  
server code

Expand|Select|Wrap|Line Numbers
  1.     protected void Button1_Click(object sender, EventArgs e)
  2.     {
  3.          //some process
  4.          //after that call javascript alert('msg'); 
  5.     }
  6.  

hope this is clear



thank you
chathura bamunusinghe

Member
 
Join Date: Aug 2008
Posts: 55
#2: Sep 1 '08

re: ASP.NET C# Calling a javascript function from asp


Expand|Select|Wrap|Line Numbers
  1. Response.Write("<script language=javascript>alert('Hello');</script>);
chathura86's Avatar
Member
 
Join Date: May 2007
Location: Homagama, Sri Lanka
Posts: 92
#3: Sep 1 '08

re: ASP.NET C# Calling a javascript function from asp


sorry but that didnt work

i got the following error

Sys.WebForms.PageRequestManagerParserErrorExceptio n: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled. Details: Error parsing near '


i trued this and it seems to be working but not sure

Expand|Select|Wrap|Line Numbers
  1.     ScriptManager.RegisterStartupScript(Page, this.GetType(), "MyMessageBox", "javascript:alert('hello')", true);
  2.  
chathura bamunusinghe
Reply