Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
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
 
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 10-May-13 3:17am
Edited 10-May-13 3:34am
RyanDev125K
v2
Comments
ryanb31 at 10-May-13 8:34am
   
You should load controls in the OnInit event instead of PageLoad. That may fix your issue.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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[^]
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 195
1 ProgramFOX 130
2 Maciej Los 105
3 Sergey Alexandrovich Kryukov 85
4 Afzaal Ahmad Zeeshan 82
0 OriginalGriff 6,564
1 Sergey Alexandrovich Kryukov 6,048
2 DamithSL 5,228
3 Manas Bhardwaj 4,717
4 Maciej Los 4,150


Advertise | Privacy | Mobile
Web02 | 2.8.1411022.1 | Last Updated 10 May 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100