开发者

javascript code in usercontrol loaded in updatepanel

开发者 https://www.devze.com 2023-01-07 07:01 出处:网络
I have an updatepanel which contains a linkbutton(such as lnk1) and a panel(such as panel1). everytime user clicks the link1, a certain usercontrol (such as uc1) loaded dynamically in panel1.

I have an updatepanel which contains a linkbutton(such as lnk1) and a panel(such as panel1). everytime user clicks the link1, a certain usercontrol (such as uc1) loaded dynamically in panel1. In uc1, I have a modalpopup that fires by a button in uc1. I want in modalpopup when user clicks background, the modalpopup hide. I know the javascript code for this but don't know where place it.

The javascript code is:

var backgroundElement = $get("<%= modalpopup.ClientID %>_backgroundElement"); 
$addHandler(backgroundElement, 'click', hidemodalpopup);
  function hidemodalpopup(){
  var modalpopup = $find("<%=modalpopup.ClientID %>");开发者_高级运维 
  modalpopup.hide();
}

I want to know where these codes should be placed to run properly.


We usually use a StringBuilder and ScriptManager.RegisterStartUpScript to create the script server side and inject it during Page_Load or Init.

protected override void OnInit(EventArgs e)
{
   StringBuilder sb = new StringBuilder();
   sb.Append("var backgroundElement = $get('" + modalpopup.ClientID+"_backgroundElement');"); 
   sb.Append("$addHandler(backgroundElement, 'click', hidemodalpopup);");
   sb.Append("function hidemodalpopup(){");
   sb.Append("var modalpopup = $find('" + modalpopup.ClientID + "');"); 
   sb.Append("modalpopup.hide();");
   sb.Append("}");
}
0

精彩评论

暂无评论...
验证码 换一张
取 消