tags:

views:

13

answers:

3

Hi Folks 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 . Thanks in advance .

A: 

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("}");
}
Rob Stevenson-Leggett
A: 

I examine several ways such as ways you said , i use ScriptManager.RegisterClientScriptBlock and Page.ClientScript.RegisterClientScriptBlock in page_load sub of usercontrol but it dont work and i get this javascript error : Object required , in fact it dont detect modalpopup .

poorna
If you didn't understand my answer you should comment on it or I will not be notified that you didn't understand. I've updated my answer with some code.
Rob Stevenson-Leggett
A: 

Any Idea,please help me .

poorna

related questions