Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a user control with some text box and a button(submit).My problem is that
when I load the aspx page I register the ascx control's button click event on the
aspx page.If click the submit button on the ascx control it is working fine
but if I put the page load events under if(!ispostback),then the button click
event not working.
As the page is already loaded so it is ambiguous to reload the control again
to get the ascx controls click event.

Kindly help me to achive that one.I don't want to load the control again.

My aspx code below

C#
protected void Page_Load(object sender, EventArgs e)
    {
       
            if (Request.QueryString["mode"] == "createTck")
            {
                UserControl_CreateTicket uccreateTicket = LoadControl("~/UserControl/CreateTicket.ascx") as UserControl_CreateTicket;
                plcHolderTicket.Controls.Add(uccreateTicket);
                uccreateTicket.evnt_btnSubmitClk += new delgbtnSubmit_Ticket(ucCreateTicket_btnSubmitClk);
            }
            else if (Request.QueryString["mode"] == "TcktHistory")
            {
                UserControl_TicketHistory ucTicketHistoey = LoadControl("~/UserControl/TicketHistory.ascx") as UserControl_TicketHistory;
                plcHolderTicket.Controls.Add(ucTicketHistoey);
            }
        

    }

    #region ButtonClick(ContentPages)
    void ucCreateTicket_btnSubmitClk(object sender, EventArgs e)
    {
        UserControl_CreateTicket ucCrateTicketControl = ((UserControl_CreateTicket)(sender));
        Response.Write(ucCrateTicketControl.Remark);

    } 
    #endregion
Posted
Updated 10-May-13 2:34am
v2
Comments
ZurdoDev 10-May-13 8:34am    
You should load controls in the OnInit event instead of PageLoad. That may fix your issue.

1 solution

You have to reload the control on every post back, because its a dynamically added control.
You can avoid the loading if you include the control in the XML markup. Then you could add both controls to the XML file and only display the one you want based on the query string.
<my_control id="createTicket">......</my_control>
<my_control2 id="historyTicket">......


if (Request.QueryString["mode"] == "createTck")
{
    createTicket.Visible = true;
    historyTicket.Visible = false;        
}
else if (Request.QueryString["mode"] == "TcktHistory")
{
    createTicket.Visible = false;
    historyTicket.Visible = true;       
}

</my_control2>

This link will explain what happens to the page when its submitted.
http://msdn.microsoft.com/en-us/library/ms178472(v=vs.100).aspx[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900