Click here to Skip to main content
15,904,652 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I am trying to make a function that takes an argument as a control name.

In this function I would like to get the client id for that control using the argument passed in the function. Example

function GetControl(str)
{
$('<%=str.ClientId%>')  // Something like that.

}


Please help.
Posted
Updated 2-Dec-10 7:56am
v2

trying to make a function that takes an argument as a control name
Rightly said but wrong implementation.

Either pass, '<%=str.ClientId%>' directly to GetControl function. In it, find the control based on it.


OR

Change the function name to GetControlID(str) and then try to do what you are doing right now. But for this, you need to pass entire control object to it. Like, a control calling itself using 'this'

I would go for previous one where one gets the control ID as a parameter then just find the control and do some changes.
 
Share this answer
 
Comments
Faisal Khatri 2-Dec-10 15:14pm    
Its not working. I tried it.

function DollarFormat(str)
{
$('#<%= str.ClientID %>').val;

}

It gives me this error "Compiler Error Message: CS0103: The name 'str' does not exist in the current context".

Any help will be appreciated. Thanks
Faisal Khatri 2-Dec-10 15:21pm    
To call the DollarFormat function i m doing this:
<asp:TextBox ID="txt" onchange="javascript:DollarFormat('txt');" runat="server" Width="250px" ></asp:TextBox>
Sandeep Mewara 3-Dec-10 14:07pm    
Well, this is wrong:
<asp:TextBox ID="txt" onchange="javascript:DollarFormat('txt');"
txt is no more a control object the way you are passing. It's a string... just string. As I said, if you want that then try:
<asp:TextBox ID="txt" onchange="javascript:DollarFormat(this);"
explain again! post some more code! I couldn't understand what you want and why do you need to pass the control name in a javascript function :thumbsdown:
 
Share this answer
 

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