Link to home
Start Free TrialLog in
Avatar of Relegence
RelegenceFlag for Israel

asked on

Getting a user control's property's value on the client side

Hello,

I am creating a c# asp.net ascx control which I want to use in my applications.
The control has a textbox and 2 images and a  property "UpDownMaxValue" which I would like to get its value on the client side, when clicking one of the images.

 I know I can get the control's value, for example,  by using:
document.getElementById('<%= txtUpDown.ClientID %>').value

How can I get the "UpDownMaxValue" on client side?

Thank you

ascx code
----------
 
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="updown.ascx.cs" Inherits="ControlsTests.updown" %>
<script language="javascript">
    function increment()
    {
       var currentVal = document.getElementById('<%= txtUpDown.ClientID %>').value
       if(!isNaN(parseInt(currentVal)))
       {
            document.getElementById('<%= txtUpDown.ClientID %>').value = Number(currentVal) + 1;
       }
    }
    
    function decrement()
    {
       var currentVal = document.getElementById('<%= txtUpDown.ClientID %>').value
       if(!isNaN(parseInt(currentVal)))
       {
            document.getElementById('<%= txtUpDown.ClientID %>').value = Number(currentVal) - 1;
       }
    }
</script>
 
<table>
    <tr>
        <td>
            <asp:TextBox ID="txtUpDown" runat="server" Width="30px"></asp:TextBox>
             <img src="images/arrUp.gif" onclick="javascript:increment()" style="position:relative; left: -4px; top: -8px;" />
             <img src="images/arrDown.gif" onclick="javascript:decrement()" style="position:relative; left: -19px; top: 3px;"/>
        </td>
    </tr>
</table>
 
cs code
--------
 public int UpDownMaxValue
        {
            get
            {
                return this.MaxVal;
            }
            set
            {
                this.MaxVal = value;
            }
        }

Open in new window

Avatar of gops1
gops1
Flag of United States of America image

Is it not possible to get the maxvalue to a javascript variable
var a=<%=UpDownMaxValue%>
This just a rough idea since I am not sure about ASP
Hi, the way to get a property is by using the following syntax: UserControlClientID:PropertyName

Try this and see if it works:
var currentVal = document.getElementById('this:UpDownMaxValue').value;

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Relegence
Relegence
Flag of Israel image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of modus_operandi
modus_operandi

Closed, 400 points refunded.
modus_operandi
EE Moderator