views:

86

answers:

2

Hello all,

I am using c#.net

I have a repeater within a View (MultiView) each row contains a ‘Edit’ button (stored on the CommandArgument is the type ID).

<asp:Button ID="buttonClick" OnCommand="ButtonClick" CommandArgument='<%#Eval("ID")%>' runat="server" Text="Edit"/>

When the user clicks on the ‘Edit’ button they are taken through to another view (Edit View).

Dependant on which type Eval("ID") is selected a different UserControl must be visible.

I have noticed that if postback occurs on the same form (Edit View) it loses its state for the dynamic control. Therefore I think I need to access/populate the DIV (appViewArea) via the Page_Load.

Within my Page_Load I only want it to populate the DIV with the correct UserControl if the user has accessed the Edit View. Here is what I currently have within my Page_Load.

if(_multiView1.ActiveViewIndex == 1) // This is the Edit View
{
  int typeId = Convert.ToInt32(viewAppointmentID.Value); // viewAppointmentID is a hidden field which is created within the ButtonClick method.

switch (typeId)
{
  case 1:
        {
          var control = Page.LoadControl("~/editBirthAppointment.ascx");
          appViewArea.Controls.Add(control); 
        }
        break;
  case 2:
        {
          var control = Page.LoadControl("~/editDeathAppointment.ascx");
          appViewArea.Controls.Add(control); 
        } 
        break;
}
}

protected void ButtonClick(object sender, CommandEventArgs e)
{
   var viewAppointmentID = Convert.ToInt32(e.CommandArgument);
   _multiView1.ActiveViewIndex = 1;
}

My problem is that it never goes into the if statament (_mutliview) and it also doesn’t store the viewAppointmentID. I have looked around the web but cannot find anything that really helps me out. Am I accessing it the wrong way?

Thanks in advance for any help.

Thanks

Clare

A: 

you don't need the page_load but the oncommand event from the grid and in that event you check the commandname and/or commandarguments

it seems that you should use

  if(!Page.IsPostback())
       // fill grid here

and in the onRowCommand event you can add the usercontrols to the page

JP Hellemons
I need to use it within the Page_Load as the dynamic control isn't stored within the ViewState.
ClareBear
you can add it to a session var with the oncommand thing and then access it in the page_load? or can you give us some more code
JP Hellemons
A: 

I added this code instead into my button event. It seems to work now so must be storing it within the ViewState.

ClareBear