Calling a method in parent page from user control

前端 未结 10 1193
暖寄归人
暖寄归人 2020-11-28 23:01

I\'ve a user control registered in an aspx page On click event of a button in the user control, how do i call a method which is there in the parent page\'s code

10条回答
  •  天涯浪人
    2020-11-28 23:26

    You can use Session . Say when you click on a button in user control and when you want to call Parent page method then in event handler of button click set value as

    Session["CallParent"]="someValue";
    

    as button will post back the page . On Page_Load event of Parent Page add it

    protected void Page_Load(object sender,EventArgs e)
    {
       if(Session["CallParent"]!=null)
       {
          // here call the Parent Page method 
          Method1();
          // now make the session value null
         Session["CallParent"]=null;
        }
    }
    

    It is much more efficient

提交回复
热议问题