2

I have loaded a user control dynamically using jquery ajax in my asp.net application.

Every thing is working fine except after the user control loaded an asp.net link button on the page is not firing the click event. The link button is not dynamically loaded.

Please help me to resolve the issue.

Thanks

Shibin V.M

html markup

logout

More

js web method calling function

 function callRefinepopUpAjax(type, id) 
 {    
    var panel_popup_layer =  $('#id');
    var val;
    if (Serach.hasOwnProperty(type))
        val = Serach[type];

    $.ajax({
        type: "POST",
        url: "../ProfileSearchService.asmx/LoadRefinePopUp",
        data: "{Type:'" + type + "',Value:'" + val + "'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(msg) {

            $(panel_popup_layer).html(msg.d);
            setUp();
        }

    });    
}

web method

public string LoadRefinePopUp(string Type, string Value)
{
    Page page = new Page();
    UserControl ctl = new UserControl();
    ArrayList list = new ArrayList();
    list.Add(Value);
    Context.Items["WebForm1List"] = list;
    try
    {
        ctl =
           (UserControl)page.LoadControl("~//popup" + Type + ".ascx");



        HtmlForm form = new HtmlForm();


        form.Controls.Add(ctl);
        page.Controls.Add(form);

        StringWriter textWriter = new StringWriter();

        HttpContext.Current.Server.Execute(page, textWriter, false);


        return CleanHtml(textWriter.ToString());
    }
    catch (Exception ex)
    {

        return ex.toString();

    }




}
Glory Raj
  • 17,397
  • 27
  • 100
  • 203
Shibin V.M
  • 411
  • 4
  • 9
  • 17

2 Answers2

0

I know that this question was asked 5 years ago but I came today and get stock with the same issue. Maybe my answer can help anyone. Based on this article you cannot fire a click event when creating your user control in this way. You have then to rely on buttons handled from client side. if you try to add your user control to your page not dynamically, events will be fired as the page is loaded (check here)

Mlle 116
  • 1,149
  • 4
  • 20
  • 53
0

you can try like this .....

NOTE : this is an example .....if you specify your user control(code) then it will be useful ....

Assuming the name of the type follows the name of the file, you can strongly-type it to that type, such that,

var myUserControl = Page.LoadControl("~/View/EditScheduleProgram.ascx") as EditScheduleProgram;

Then you have access to any custom (or specific) events exposed by that type but not by Control, so,

myUserControl.MyEvent += MyEventHandler;
Glory Raj
  • 17,397
  • 27
  • 100
  • 203