Click here to Skip to main content
15,907,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a usercontrol with inbuilt js functions to validate all the controls inside it.The usercontrols is incorporated in 3 aspx pages and it works fine with 2 aspx pages but one although all three aspx pages do not contain any js of their own.

Whenever i click the submit button of the ascx file the js function is not fired at all even if i write alert in it.It gives an error (Object Expected).
Posted
Updated 19-Oct-11 20:52pm
v2
Comments
RaisKazi 20-Oct-11 2:50am    
Your code please.
Sanchit Rana 20-Oct-11 3:02am    
Hi RaisKazi,
Thanks for the response.Here is the sample code.

function test() {
alert('test');
}

<asp:linkbutton id="lnkSubmit" runat="server" validationgroup="User" cssclass="action" onclick="lnkSubmit_Click" onclientclick="return test();" xmlns:asp="#unknown">Submit

The above code is inside the usercontrol and works alright when added to 2 aspx pages but not the third one.

The third page gives a JS error upon click of submit button even if it doesn't contain JS of its own.
Sanchit Rana 20-Oct-11 3:19am    
Any Suggestions ?

May be in 3rd aspx page there is also test() function. please check.
 
Share this answer
 
Comments
Sanchit Rana 20-Oct-11 5:24am    
Thanks Amar .. I have already found the soln.. Look at solution 1..
just check the code by right click and view HTML source, you wont find test function on the page. If this is the case means you have to get the test function on page load of your third page. Its not getting loaded on that page.

you can create your test function in this way
XML
public void RegisterClientScript()
        {

            StringBuilder cstext2 = new StringBuilder();
            cstext2.Append("<script type=\"text/javascript\">  function Test() {");
            cstext2.Append("alert('Test');}");
            cstext2.Append(" </script>");
            ScriptManager.RegisterClientScriptBlock(this, GetType(), "OnClientItemSelected", cstext2.ToString(), false);
        }


and can call this method on the page load of your third page.
UcControl.RegisterClientScript();

Hope it works
 
Share this answer
 
Comments
Sanchit Rana 20-Oct-11 5:24am    
Thanks Anuja .. I have already found the soln.. Look at solution 1

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