Cant invoke jquery function from asp.net code behind.
in Using jQuery
•
11 years ago
Im new to javascript/Jquery
I have made a javascript/Jquery applet witch i will use to display feedback from my asp.net application to the end user. Like a fancy pop up that slides in and have different functionality depending if the message is of status "error" "alert" or "success".
(I know this has been done before and there are plug ins and stuff to do it. Im not posting this cause i need the solution solved, im posting because i need to understand what i am doing wrong and learn how to properly invoke my js/jq functions.)
The asp.net codebehind method that invokes the jq function uses the RegisterClientScriptBlock(); The method works if i just put alert("whatever"); instead of invoking the pop up function. If i make a dummy js function outside of the document ready it also works. But when i try and invoke my pop up alert function nothing happens. It doesnt even go inside the function.
C#
- public void SendPopUp()
- {
- message = message.Replace("'", "\\'");
- title = title.Replace("'", "\\'");
- string key = "opoopop"; //Guid.NewGuid().ToString();
- StringBuilder javascript = new StringBuilder();
- javascript.Append("$(document).ready(function() {");
- javascript.Append(" AlertPopUp('Horror', 'Oh nooo, an error is simulated!', 'error');");
- // javascript.Append(" var stringg = 'hej'; alert(stringg);");
- javascript.Append(" });");
- // Gets the executing web page
- Page page = HttpContext.Current.CurrentHandler as Page;
- ScriptManager sm = ScriptManager.GetCurrent(page);
- if (sm != null && sm.IsInAsyncPostBack)
- {
- ScriptManager.RegisterClientScriptBlock(page, typeof(Page), key,javascript.ToString() , true);
- }
- else
- {
- page.ClientScript.RegisterClientScriptBlock(this.GetType(), key,javascript.ToString() , true);
- }
- }
1