views:

232

answers:

1

Hi,I have a usercontrol.Inside usercontrol I have a datalist and sqldatasource.Sqldatasource needs a parameter to databind the datalist.Usercontrol gets a paramter by this way,

  private string _urunIDparam;
    public string urunIDparam
    {
        get { return _urunIDparam; }
        set {_urunIDparam = value; }
    }

And then this parameter is added to the sqldatasource in onprerender of usercontrol by this way,

protected override void OnPreRender(EventArgs e)
{
    SqlDataSourceHareketler.SelectParameters["urunID"].DefaultValue = urunIDparam;
    DataListHareketAna.DataBind();
    base.OnPreRender(e);
}

And the usercontrols parameter is given from a button that is placed aspx page like this,

protected void Button1_Click(object sender, EventArgs e)
{
    MyUserControl1.urunIDPARAM = urunID;
}

And button and usercontrol is placed in an updatepanel inside an aspx page like this,

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
        <uc2:MyUserControl ID="MyUserControl1" runat="server" /> 
         <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click"/>
    </ContentTemplate>
</asp:UpdatePanel>

And the problem when I hit a button inside datalist ,my usercontrol dissappears(datalist loses its items).Any help is appreciated.Thanks.

+1  A: 

It sounds like you may need to do a postback check around your functions within the controls. I have seen this exact issue before, and I think this is what I had to do, but it has been awhile.

if (!IsPostback) {
  //LoadData
}
RSolberg
thanks for your clue but I've already try ispostback but the problem continues.
slayer35