How to call jscript func in user control from parent aspx page

M

moondaddy

from a html button (btnTest) on a aspx page (main.aspx) I need to call a
java script function in a user control (ItemGrid4col ) which is nested in a
panel control (Panel1). This function (TestFunc) in the user control will
make the user control do a postback. The reason I'm using a html button in
main.aspx is so it wont do a postback. How can I call TestFunc in the user
control from btnTest (or a function in main.aspx which btnTest would fire on
its Onclick event)?


<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">

<INPUT style="Z-INDEX: 109; LEFT: 32px; WIDTH: 80px; POSITION: absolute;
TOP: 272px; HEIGHT: 40px" type="button" value="btnTest" >

<asp:panel id="Panel1" style="Z-INDEX: 108; LEFT: 184px; POSITION:
absolute; TOP: 96px" runat="server" Width="152px" Height="160px">
<ItemGrid:ItemGrid4col id="ItemGrid4col1" runat="server"
EnableViewState="False"></ItemGrid:ItemGrid4col>
</asp:panel>
</form>
</body>


Thanks.
 
J

Jeffrey Tan[MSFT]

Hi moondaddy,

Thank you for using MSDN Newsgroup! My name is Jeffrey, and I will be
assisting you on this issue.

Based on my understanding, you got a usercontrol on the web form and there
is client javascript code in this user control. You want to call the
javascript code in your user control from html button.

==================================================================
Actually, user control will render all the client javascript code to the
web page, so you can just call these code as you call the javascript code
in the web page.

I have writen a sample like this:
1). Add a user control to your web form, below is the user control's code:
<script language=javascript>
function func()
{
alert("called");
}
</script>

2). Drag this user control to the web form, and invoke func() in html
button:
<INPUT onclick="func()" style="Z-INDEX: 109; LEFT: 32px; WIDTH: 80px;
POSITION: absolute;TOP: 272px; HEIGHT: 40px" type="button" value="btnTest" >

===================================================================
Please apply my suggestion above and let me know if it helps resolve your
problem.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
J

Jeffrey Tan[MSFT]

Hi moondaddy,

Thanks for your feedback.
I am glad it works.
If you have any further concern, please feel free to post in this group. I
will work with you!
Have a nice experience on using Microsoft Newsgroup!

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top