Solved

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

Posted on 2007-11-26
5
640 Views
Last Modified: 2010-05-18
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

0
Comment
Question by:Relegence
5 Comments
 
LVL 17

Expert Comment

by:gops1
ID: 20349073
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
0
 
LVL 10

Expert Comment

by:joex911
ID: 20349537
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

0
 

Accepted Solution

by:
Relegence earned 0 total points
ID: 20349626
joex911: - I got an "Object Required" error message
It got it working by sending the value of the parameter i needed in the call to the javascript function -
onclick="javascript:increment('<%= txtUpDown.ClientID %>', <%=MaxVal%>)"

MaxVal is a protected variable in the code behind which was set using the property's "set" method.
That is what solved the problem
0
 
LVL 1

Expert Comment

by:modus_operandi
ID: 20588038
Closed, 400 points refunded.
modus_operandi
EE Moderator
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now