Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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;
        }
    }
 
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 1-Nov-12 19:58pm
Comments
ryanb31 at 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)

  Print Answers RSS
0 Richard MacCutchan 269
1 Aajmot Sk 252
2 Marcin Kozub 235
3 Sergey Alexandrovich Kryukov 185
4 Praneet Nadkar 167
0 OriginalGriff 7,913
1 Sergey Alexandrovich Kryukov 7,232
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,865


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 2 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100