Click here to Skip to main content
15,886,734 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
XML
I have created a user control.
WebUserControl.ascx
<script type="text/javascript">
    function btnShowPopUp_Click() {
        $find('popUp').show();
        return false;
    }

    function btnCancel_Click() {
        $find('popUp').hide();
        return false;
    }

    function btnOK_Click() {
        //I have to do some logic here but don't know
    }
</script>
<asp:Button ID="btnHidden" runat="server" Style="display: none;" />
<asp:Button ID="btnShowPopUp" runat="server" OnClientClick="return btnShowPopUp_Click();"Text="Enter Number" />
<asp:UpdatePanel ID="updatePanel1" runat="server">
    <ContentTemplate>
        <div style="background: #f8f8f8; border: solid 2px #080808; padding: 15px;">
            <asp:Label ID="lblNumber" Text="Number" runat="server" />
            <asp:TextBox ID="txtNumber" runat="server" />
            <br />
            <asp:Button ID="btnOK" runat="server" OnClientClick="return btnOK_Click();" Text="OK" />
            <asp:Button ID="btnCancel" runat="server" OnClientClick="return btnCancel_Click();"Text="Cancel" />
        </div>
    </ContentTemplate>
</asp:UpdatePanel>
<asp:ModalPopupExtender ID="modalPopUp1" runat="server" BehaviorID="popUp" PopupControlID="updatePanel1"
    TargetControlID="btnHidden" />

And then added two properies in code behind.
WebUserControl.ascx.cs
<pre lang="c#"> private string _assLabel = "";
    public string AssociatedLabelID
    {
        get
        {
            return _assLabel;
        }
        set
        {
            _assLabel = value;
        }
    }

    private string _assTextBox = "";
    public string AssociatedTextBoxID
    {
        get
        {
            return _assTextBox;
        }
        set
        {
            _assTextBox = value;
        }
    }

ASP.NET
Default.aspx
<asp:Label ID="lblFirstNum" runat="server" Text="Enter First Number" />
        <asp:TextBox ID="txtFirstNum" runat="server" />
        <uc1:WebUserControl ID="wucFirst" AssociatedLabelID="lblFirstNum" AssociatedTextBoxID="txtFirstNum"  runat="server" />
        <br />
        <asp:Label ID="lblSecondNum" runat="server" Text="Enter Second Number" />
        <asp:TextBox ID="txtSecondNum" runat="server" />
        <uc1:WebUserControl ID="wucSecond" AssociatedLabelID="lblSecondNum" AssociatedTextBoxID="txtSecondNum"  runat="server" />

Now what I have to do is that when I first click 'wucFirst' it will show me PopUp which is in the user control.  When I enter some values in 'txtNumber' and click OK button I want to assign that value in AssociatedTextBoxID or if click 'wucSecond' and enter value in 'txtNumber' and click OK button I want to assign value in 'wucSecond's AssociatedTextBoxID.
Posted
Comments
ZurdoDev 2-Nov-12 16:40pm    
If you want to get the property values in JavaScript you'll have to write them to a hidden field on the page. Then JS can have access to them.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900