Dinesh Ambaliya

Dinesh Ambaliya

  • NA
  • 42
  • 80.1k

How to get properties value of web user control using JavaScript.

Nov 2 2012 2:21 AM

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

    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.