I have a user control with a button on it, on button click i want execute a Javascript
pop up using the ScriptManager
and return to the parent page to do a response.redirect. But for some reason my Javascript
is not getting executed. I have noticed that if i remove the response redirect on the parent the Javascript
execution works fine.
Below is my code:
UserControl:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace RegisterDemo
{
public partial class RegisterUserControl : System.Web.UI.UserControl
{
public delegate void customHandler(object handler);
public event customHandler SendtoParent;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void usercontrolbutton_Click(object sender, EventArgs e)
{
ScriptManager.RegisterStartupScript(this, GetType(), "validator", "alert('Error');", true);
SendtoParent(sender);
}
}
}
Parent Page:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace RegisterDemo
{
public partial class _Default : Page
{
protected void Page_Load(object sender, EventArgs e)
{
MyUserInfoBoxControl.SendtoParent += new RegisterUserControl.customHandler(onusercontrolevent_click);
}
protected void DemoButton_Click(object sender, EventArgs e)
{
//ScriptManager.RegisterStartupScript(this, GetType(), "validator", "alert('u click this button');", true);
}
protected void onusercontrolevent_click(object sender)
{
ScriptManager.RegisterStartupScript(this, this.Page.GetType(), "event", "alert('event completed');", true);
Response.Redirect("www.google.com");
}
}
}
Can someone please help me find out how to get the Javascript
in my UserControl
to execute? What am i missing here?