Quantcast
Channel: ASP.NET AJAX + Ajax Control Toolkit (ACT)
Viewing all articles
Browse latest Browse all 5678

User Control Event Handler lost after postback

$
0
0

I have a web page calling the user control to get a message as additional information before saving the record, but the save event was passed correctly, but lost after the user click save in User Control as the Save button in User Control trigger a postback. I would like to know how can I add the event handler back to the User Control so that it can pass the correct event back to the web page and call the correct Save method in web page.

Web Page

    <uc:MessageForm ID="ucComment" runat="server" />

BUT

    <uc:MessageForm ID="ucComment" runat="server" OnSave="btnSaveEmployee" />

Works. But I don't want to have two <ucMessageForm> user controls in one page. 

Web Page Codebehind

    protected void btnGetEmployeeComment(object sender, EventArgs e)
    {
        ucComment.Save += this.btnSaveEmployee;
        ucComment.GetMessage(ID);
    }

    protected void btnGetClientComment(object sender, EventArgs e)
    {
        ucComment.Save += this.btnSaveClient;
        ucComment.GetMessage(ID);
    }

    protected void btnSaveEmployee(object sender, EventArgs e)
    {
         Comment = ucComment.Comment;
         //Save Employee record
    }
    protected void btnSaveClient(object sender, EventArgs e)
    {
         Comment = ucComment.Comment;
         //Save Client record
    }

AND a user control as ModalPopup

<asp:TextBoxID="txtComment"runat="server"CssClass="ModalFormMemoInput"MaxLength="8000"TextMode="MultiLine"/>
<asp:ImageButtonID="btnSave"runat="server" ImageUrl="~/Images/ButtonSave.gif"OnClick="btnSave_Click" />

User Control Code behind

    private EventHandler _save;
    public event EventHandler Save
    {
        add
        {
            _save += value;
        }
        remove
        {
            _save -= value;
        }
    }

    protected void btnSave_Click(object sender, EventArgs e)
    {
        mpeMessage.Hide();
        if (_save != null)
            _save(this, e);
    }
   
    public void GetMessage(string ID)
    {
        mpeMessage.Show();
    }


Viewing all articles
Browse latest Browse all 5678

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>