Click here to Skip to main content
15,899,126 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
javascript:
JavaScript
function setPropertyLocation() {
            alert('Hello');
        }



c# :
C#
Button btnMap = new Button();
btnMap.Attributes.Add("type", "button");
btnMap.Attributes.Add("title", "Map");
btnMap.UseSubmitBehavior = false;
btnMap.OnClientClick = "setPropertyLocation();return false";
btnMap.ID = "btnMap" + objPMPropTypestructure.PMFields[fieldcnt].SystemName;
btnMap.CssClass = "dataButton";
btnMap.Text = "G";
btnMap.Enabled = true;
tc2.Controls.Add(btnMap); //tc2 = tablecell


getting error as:
Uncaught ReferenceError: setPropertyLocation is not defined
Posted
Updated 18-Sep-15 3:31am
v5
Comments
Afzaal Ahmad Zeeshan 18-Sep-15 9:07am    
Make sure that the setPropertyLocation is accessible in the scope you are calling from.
Grant Weatherston 18-Sep-15 10:14am    
Like Afzaal says make youre javascript function is accessible, especially if using a modular JS design pattern. Also double check that your js file where the function lays is being rendered into the page (view page source).

1 solution

first of all check that you javascript function is accessible from the button OR
You can try this
C#
btnMap.Attributes.Add("onclick", "setPropertyLocation();");
 
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