473,387 Members | 3,033 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

I need to call a javascript function from C# code. I am getting object expected error

Expand|Select|Wrap|Line Numbers
  1. //javascript function
  2. <script language="javascript" type="text/javascript">  
  3.        function popModal() {   
  4.            $find('ModalPopupExtender').show();            
  5.        }    
  6.  
  7. </script>  
  8.  
  9. //C# code
  10.  
  11. protected void Page_Load(object sender, EventArgs e)
  12. {
  13.    if (!Page.IsPostBack)
  14.    {
  15.       string script = "<SCRIPT LANGUAGE='JavaScript'> ";
  16.       script += "popModal();";
  17.       script += "</SCRIPT>";
  18.   this.RegisterClientScriptBlock("ClientScript", script);
  19.      }
  20.  }
  21.  
Jun 24 '10 #1
3 1629
Frinavale
9,735 Expert Mod 8TB
Well you're getting that message because JavaScript couldn't not find an element with the ID "ModalPopupExtender". You need to provide the ID of the the ModalPopupExtender to the method. You can do this using the ClientID of the ModalPopupExtender.

Like this:
Expand|Select|Wrap|Line Numbers
  1. protected void Page_Load(object sender, EventArgs e)
  2. {
  3.    if (!Page.IsPostBack)
  4.    {
  5.       string script = "<SCRIPT LANGUAGE='JavaScript'> ";
  6.       script += "popModal(" + ModalPopupExtender1.ClientID + ");";
  7.       script += "</SCRIPT>";
  8.   this.RegisterClientScriptBlock("ClientScript", script);
  9.      }
  10.  }
You'll have to change your JavaScript to accept the ID of the ModalPopupExtender as a parameter...and use that with the $find method:
Expand|Select|Wrap|Line Numbers
  1. //javascript function
  2. <script language="javascript" type="text/javascript">  
  3.        function popModal(ModalPopupExtenderClientID) {   
  4.            $find(ModalPopupExtenderClientID).show();            
  5.        }    
  6.  
  7. </script> 
Jun 24 '10 #2
@Frinavale
Thank you for your quick response.

But I still get the same error.

I tried like below also

script += "popModal('" + ModalPopupExtender1.ClientID + "');";
Jun 24 '10 #3
Frinavale
9,735 Expert Mod 8TB
What exactly are you trying to do?
The ModalPopupExtender has it's own JavaScript aspect that it uses to display itself. You shouldn't be trying to find it on the page...you should be calling it's methods to display it.

-Frinny
Jun 24 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: TAM | last post by:
Hi, I have a simple JavaScript code that ensures that all the form fields are filled and there is also a function that checks if the email is a valid address. For some reason IE is giving...
4
by: Kiyomi | last post by:
Hello, I am trying to replace my alert message box with a popup page. In my page behind,
4
by: loserdude84 | last post by:
Hi I keep getting the good old error 'Object Expected Error' on a site I recently built. I am really struggling with this one. Object Expected Error Line 66 <div...
0
by: AncaT | last post by:
Hi, I have just started working w/ asp.net, vb.net. I have a .aspx page that contains user defined controls. Inside these controls, I have a 'Delete' hyperlink. This is the code: Inside...
4
by: verci | last post by:
Hi guys, I'm running asp.net 2.0. Does anyone know how to fire or call a javascript function from inside my (VB.aspx) code without assigning it to a control attribute? thank you
2
by: snowburnt | last post by:
hi, I'm trying to script a simple class change and it isn't working. when I script it into the event handler of the tag it works fine, however, I want more to happen with it in the long run...
1
by: JOJO123 | last post by:
I got here in search of an answer to this Javascrpt question. I upgraded jave on XP Ie 7, acrobat 5.1 and suddenly can't open any pdf files on web sites using IE. I see u guys all say, this is a...
1
by: tgorton | last post by:
I am having a problem running a javascript function as part of an html-el:form onsubmit. The problem seems to exists in IE6 but not in Firefox. html: <html-el:form action="${target}"...
2
by: jc | last post by:
I'm trying the below and getting OBJECT EXPECTED error in javascript. On my aspx page I have this java script block: <script language="javascript" type="text/javascript"> function...
5
renji1981
by: renji1981 | last post by:
Hi Pals Im getting Object Expected Error and Im new to Ajax . I have pasted the Html code here .. please help . <html> <head> <title>My first ajax Application </title> <script...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.