Share your homepage and content on an asp.net page

Suppose I have one downpound on the main page, and I want that when the user selects an item from this drop-down list, a reverse transfer occurs and the text of the selected item will be displayed on the label of the content page. please help me with a sample code.

thank

+3
source share
4 answers

The following directive should be added to the content page:

<%@ MasterType VirtualPath="path to master page" %>

Add the public property ih file of the main page:

public DropDownList DropDownList
{
    get { return dropDownList; }
}

Add an event handler on the content page:

Master.DropDownList.SelectedIndexChanged += OnSelectedIndexChanged;

Assign Master.DropDownList.SelectedValue to Label.Text in the hanlder event.

+4
source

On the home page:

<asp:DropDownList ID="someDropDown" runat="server" AutoPostBack="True">
<asp:ListItem Text="Bob" Value="Bob"></asp:ListItem>
<asp:ListItem Text="John" Value="John"></asp:ListItem>
<asp:ListItem Text="Mark" Value="Mark"></asp:ListItem>
</asp:DropDownList>

On any other page in aspx:

<asp:Label ID="userLabel" runat="server"/>

, :

protected void Page_Load(object sender, EventArgs e)
    {
        DropDownList thisDropDown = this.Master.FindControl("someDropDown") as DropDownList;
        userLabel.Text = thisDropDown.SelectedValue;
    }
+3

Only one sample

MasterPageCode:

Public Class MyMasterPage
inherits Page (or MasterPage?)

public readonly property MyDropDown as DropDown
end Property

End Class

COde Page

Public Class MyContentPage
inherits Page

Public Overrides Sub OnLoad
       dim drop as DropDown = CType(Me.MasterPage, MyMasterPage).MyDropDown
       AddHandler drop.SelectedIndexChanged, AddressOf someprocedure
End Sub

End Class
+2
source

Source: https://habr.com/ru/post/1791663/


All Articles