AliRıza Adıyahşi
AliRıza Adıyahşi

Reputation: 15866

Web User Control get parent control ID?

ASCX

<dx:ASPxGridViewExporter ID="ASPxGridViewExporter1" runat="server">
</dx:ASPxGridViewExporter>

<dx:ASPxButton ID="buttonSaveAs" runat="server" ToolTip="Export and save" Style="vertical-align: middle;"
                OnClick="buttonSaveAs_Click" Text="Save" Width="51px" />

ASPX that include above ASCX

<div>
    //ASCX
</div>
<div>
    <dx:ASPxPivotGrid ID="ASPxPivotGridElectricMeterReadings" runat="server" ClientIDMode="AutoID"
        DataSourceID="SqlDataSourceElectricMeterReadings" EnableCallBacks="False" Width="1000px">
    </dx:ASPxPivotGrid>
</div>

ASCX.cs

protected void buttonSaveAs_Click(object sender, EventArgs e)
{
    // I want to get pivotGridId from ASPX
    ASPxGridViewExporter1.ASPxPivotGridID = ASPX-PivotGrid-ID
}

How can I pass ASPX control ID to ASCX button_click_event?

Upvotes: 0

Views: 2138

Answers (2)

Tamilselvan K
Tamilselvan K

Reputation: 1221

Try, declaration of the parent control, in page load event(User Control) and must be outside the postback event.

 (this.Parent.Parent).FindControl("ErrLabel") as Label;

Upvotes: 0

Ceres
Ceres

Reputation: 3668

Simply add a property to your ascx code behind and populate it in the aspx initialize event.

ASCX.cs

public string PivotGridID { get; set; }

ASPX.cs

if (!IsPostBack)
{
    exportPivotGrid.PivotGridID = ASPxPivotGridElectricMeterReadings.ID;
}

Upvotes: 1

Related Questions