public partial class VisualWebPart1UserControl : UserControl
{
public string SetId{ get; set; }
protected void ddl_SelectedIndexChanged(object sender, EventArgs e)
{
SetId = ddl.SelectedItem.Value;
}
}
WebPart Implementation (VisualWebPart1.cs)
public class VisualWebPart1 : WebPart
{
private const string _ascxPath = @"~/_CONTROLTEMPLATES/mypath/VisualWebPart1/VisualWebPart1UserControl.ascx";
protected override void CreateChildControls()
{
//generated by visual studio
//Control control = Page.LoadControl(_ascxPath);
//Controls.Add(control);
var control = (VisualWebPart1UserControl) Page.LoadControl(_ascxPath);
if (!string.IsNullOrEmpty(control.SetId)) //<<<NULL
{
}
}
}
UPDATED:
Below code is what I have in my usercontrol.ascx page and my question is how can I access the dropdownlist or textbox from outside the page. which is: class1.cs
<tr>
<td>
<fieldset title="Configured Tabs">
<legend>Configured Tabs</legend>
<asp:Panel ID="panelConfiguredTabs" runat="server">
<table cellpadding="5px" cellspacing="5px">
<tr style="padding-top: 5px; padding-bottom: 5px">
<td>
<asp:Label runat="server" ID="labelConfiguredTabs" Text="Tab list:"></asp:Label>
</td>
<td colspan="2" align="right">
<asp:DropDownList ID="dropDownConfiguredTabs" runat="server" EnableViewState="true"
AutoPostBack="true" OnTextChanged="dropDownConfiguredTabs_OnTextChanged">
<asp:ListItem Text="Select one" Value="Select one"></asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr style="padding-top: 5px">
<td align="center">
<asp:Button runat="server" ID="buttonAddNewTab" Text="Add New" OnClick="ButtonAddNewTab_OnClick"
CausesValidation="false" />
</td>
<td align="center">
<asp:Button runat="server" ID="buttonEditTab" Text="Edit" OnClick="ButtonEditTab_OnClick"
CausesValidation="false" />
</td>
<td align="center">
<asp:Button runat="server" ID="buttonDeleteTab" Text="Delete" OnClick="ButtonDeleteTab_OnClick"
CausesValidation="false" />
</td>
</tr>
</table>
</asp:Panel>
</fieldset>
</td>
</tr>
I am working on the custom web part bit advance topic.
I have a created visual web part (creates usercontrol.ascx and .cs file)
So on the root I have a class and I am trying to access the prop/method of usercontrol.ascx, how can I do that?