1

I have some ASP.NET user control named myUserControl.

I also have some aspx page named myAspxPage.

myAspxPage contains myUserControl and also myAspxPage contains this javascript function:

     function SetProgressBar() 
     {
          //some logic          
     }

at some point I need to call SetProgressBar javascipt function when this button:

 <asp:LinkButton ID="prevItem" runat="server" ToolTip="previous" Style="color: #000000;" OnClientClick="to call SetProgressBar function"> << </asp:LinkButton>

is clicked in myUserControl.

I tryed this:

  OnClientClick="parent.SetProgressBar()"

and this:

OnClientClick="SetProgressBar()"

But examples above not work.

So my question is any idea how can I call javascript function in the parent page from user control?

1
  • "examples above not work" - based on what? The second variant is fine. Commented Mar 15, 2016 at 18:02

2 Answers 2

2

I think if you add

ClientIdMode="static"

to your button and take out the OnClientClick="" so it looks like this:

 <asp:LinkButton ID="prevItem" runat="server" ToolTip="previous" Style="color: #000000;" ClientIdMode="static"> << </asp:LinkButton>

and then use onclick directly in the javascript like this:

document.getElementById("prevItem").onclick = function SetProgressBar(){

// some logic

}

That should work...

Sign up to request clarification or add additional context in comments.

Comments

1

Usercontrol is not a separate page when it is added inside any aspx page everything is rendered as a single page so in short there is no parent-child kind of thing between aspx page and usercontrol.

You should be able to call any javascript function from usercontrol.

ClientIDMode=static is not required if you are calling a function using onClientClient=.

So to test whether the function is being triggered or not, please put an alert in the first line of the function and see if it gets alert or not.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.