Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 592
  • Last Modified:

How to call a javascript function from asp.net user control

Hi, I have built an asp.net user control and in it is a textbox named demo1 and an image.  When click on the image, a pop up .js function will appear and the textbox name is passed to the function.  The function does some operations and pass back value to that text box.

However, when i run my program that calls the user control and click on the image, i get a javascript error message -> object required and the error lies in the textbox name that cannot be passed to the function.  What may be the problem?

My codes:
rpt.aspx
_______
<%@ Register TagPrefix="uc" TagName="calendar" src="uc_calendar.ascx" %>
<html><head></head>
<table>
<tr><td><uc:calendar id="caltest1" runat="server"></uc:calendar></td></tr>
</table>
</html>

uc_calendar.ascx
______________
<%@ Control Language="vb" AutoEventWireup="false" Codebehind="uc_calendar.ascx.vb" Inherits="Homepage.uc_calendar" TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %>
<LINK href="ens_style.css" type="text/css" rel="stylesheet">
<script language="javascript" src="datetimepicker.js" type="text/javascript"></script>
<SPAN class="clsDatePicker" id="span5a" style="WIDTH: 120px"><INPUT id="chk4" type="checkbox">
      <SPAN id="span5b" style="WIDTH: 65px"></SPAN>&nbsp;&nbsp;
      <asp:textbox id="demo2" runat="server" BorderStyle="None" Width="64px" Height="18px"></asp:textbox>
      <a href="javascript:setCoords(this); NewCal('this.demo2','ddmmyyyy', false, false)">
            <IMG class="clsClickable" id="img3" src="..\Homepage\Graphic\btncd.gif" align="absMiddle" border="0"></a>
</SPAN>

if i remove the textbox from the uc_calendar.ascx and put it in the webform rpt.aspx, then there is no error.  But i want the entire code to be embedded in the user control.  How do i do this?

Pls help.

Tks!



0
angelinemb
Asked:
angelinemb
1 Solution
 
nimaigCommented:
Can you please paste the generated HTML code (use 'view source' of browser) for the page.
0
 
angelinembAuthor Commented:
Thanks for your comment.  I looked into my HTML code and found the problem.  now i pass it using

<a href="javascript:setCoords(this); NewCal('usercontrol:demo2','ddmmyyyy', false, false)">


and it works!
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now