Solved

Correct my Javascript syntax ?

Posted on 2012-03-13
20
358 Views
Last Modified: 2012-03-15
Whats wrong in my following syntax ?

string javascript = "<script type='text/jscript'> " +
"$(document).ready(function () { " +
"$('" + "#" + this.ClientID + "').datepicker('" +
"'{ showOn: '" + "button" +"',buttonImage: '"
+ "images/calendar.gif,buttonImageOnly: true}); ); "
+ "});</script>";

Page.ClientScript.RegisterStartupScript(this.GetType(), this.ClientID, javascript);
0
Comment
Question by:PeteEngineer
  • 8
  • 7
  • 3
  • +1
20 Comments
 
LVL 13

Accepted Solution

by:
ansudhindra earned 200 total points
ID: 37718661
try this..

string javascript = "<script type='text/jscript'> " + 
"$(document).ready(function () { " + 
"$('#" + this.ClientID + "').datepicker(" + 
"{ showOn: 'button',buttonImage: " +
"'images/calendar.gif',buttonImageOnly: true}); ); "+
"});</script>"; 

Page.ClientScript.RegisterStartupScript(this.GetType(), this.ClientID, javascript);

Open in new window

0
 
LVL 15

Assisted Solution

by:santhimurthyd
santhimurthyd earned 250 total points
ID: 37718714
Tried to fix the issue and felt as it's difficult until we don't as what's your final syntax requirment but follow the steps to correct the syntax

Instead of registering the script usign the
Page.ClientScript.RegisterStartupScript(this.GetType(), this.ClientID, javascript);


Declare the string varaible at class level instead of Method level as show below

protected string javascript = string.Empty;

Open in new window


In the .aspx page place the belwo syntaxt to get the Script generated
<%=javascript%>

Open in new window


finally following the step script generated is as follows

 
<script type='text/jscript'> 
            $(document).ready(function () 
            { 
                $('#__Page').datepicker([b]''{ showOn: 'button',buttonImage: 'images/calendar.gif,buttonImageOnly: true}); ); });[/b]            
        </script>

Open in new window


bolded the place where the issue is, If you can possible as what's your expected script will help to fix the syntax error.
0
 
LVL 7

Expert Comment

by:wdfdo1986
ID: 37718724
yeah as ansudhindra corrected you have included some extra quotations there. Best way to test the code is first use it in an test html file and check it.
0
 
LVL 8

Author Comment

by:PeteEngineer
ID: 37718825
This  is my expected :

<script>
      $(function() {
            $( "#datepicker" ).datepicker({
                  showOn: "button",
                  buttonImage: "images/calendar.gif",
                  buttonImageOnly: true
            });
      });
      </script>


But the one "ansudhindra"  posted is not working :-(

Please correct and post !
0
 
LVL 15

Expert Comment

by:santhimurthyd
ID: 37718879
Try with this

 javascript = "<script type=\"text/jscript\"> $(document).ready(function () { " +
                    "$(\"#datepicker\").datepicker({showOn:\"button\",buttonImage:\"images/calendar.gif\"," +
                    @"buttonImageOnly: true}); });</script>";
0
 
LVL 7

Assisted Solution

by:wdfdo1986
wdfdo1986 earned 50 total points
ID: 37718897
santhimurthyd's concept is right but as I know to access a variable which is created n the back end code from the front end you need to make it a property. However that's the way I am doing when I wanted to do what you tries to do.

And if you want to continue this try this
string javascript = "<script> $(function() { $(\"" + "#" + this.ClientID + "\").datepicker(\"{ showOn: \"button\", buttonImage: \"images/calendar.gif\" ,buttonImageOnly: true}); }); </script>";
0
 
LVL 15

Expert Comment

by:santhimurthyd
ID: 37719047
I'm trying with the Page.register script only and not with the Varaible access

  javascript = "<script type=\"text/jscript\"> $(document).ready(function () { " +
                    "$(\"#datepicker\").datepicker({showOn:\"button\",buttonImage:\"images/calendar.gif\"," +
                    @"buttonImageOnly: true}); });</script>";

            Page.ClientScript.RegisterStartupScript(typeof(string), Guid.NewGuid().ToString(), javascript);


This is the syntax, I did and got error due to non reference to JQuerry Library.

If possible share the error else "Uncheck" the option disbale Javascript debuggin in IE to find where is the error your getting will help us

i) Open IE
ii) Navigate to "Tools" => "Internet Options"
iii) Navigate to "Advance Tab"
iv) Uncheck checkbox "disbale Script Debugging" under the Browser category

share your steps to help further
0
 
LVL 8

Author Comment

by:PeteEngineer
ID: 37719086
santhimurthyd :


Ahhhh..insted of #datepicker i am using client id can u rewrite that for me ?
0
 
LVL 15

Expert Comment

by:santhimurthyd
ID: 37719101
Cool , In the below change the bolded text with the respective DataPicker Id

javascript = "<script type=\"text/jscript\"> $(document).ready(function () { " +
                    "$(\"#" + <<datepicker>>.ClientID +"\").datepicker({showOn:\"button\",buttonImage:\"images/calendar.gif\"," +
                    @"buttonImageOnly: true}); });</script>";
0
 
LVL 8

Author Comment

by:PeteEngineer
ID: 37719111
See this :

"$('" + "#" + this.ClientID + "').datepicker('" +
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 13

Expert Comment

by:ansudhindra
ID: 37719117
make it just
"$('#" + this.ClientID + "').datepicker('" +
0
 
LVL 15

Expert Comment

by:santhimurthyd
ID: 37719130
this.ClientID  will return you the page Id as "__Page" to get the Datapicker Control Id, you have to use Datapicker Control Id instead of this.
0
 
LVL 8

Author Comment

by:PeteEngineer
ID: 37719210
no ..its working for the code that i posed above in my question ... u just need to change the syntax ... no change in code contents required ..please put the this.clientid and rewrite the code you have posted
0
 
LVL 8

Author Comment

by:PeteEngineer
ID: 37719341
Almost worked but few more issue


  string javascript = "<script type=\"text/jscript\"> $(document).ready(function () { " +
                    "$(\"#" + this.ClientID +"\").datepicker({showOn:\"button\",buttonImage:\"calendar.gif\"," +
                    @"buttonImageOnly: true}); });</script>";


The above code i have rewritten to read the calender.gif which is not in image folder.
The earlier one was not in image folder. Not its in root folder.

But i am getting an javascript error ..please fix it for me too
0
 
LVL 8

Author Comment

by:PeteEngineer
ID: 37719342
The previous code is working which take image from image folder

the above one is not as i am taking it NOT from image but from root.. :-(
0
 
LVL 7

Expert Comment

by:wdfdo1986
ID: 37719398
Post the JavaScript error
0
 
LVL 15

Expert Comment

by:santhimurthyd
ID: 37719438
What's the control Id needs to be in the "$(\"#" + this.ClientID +"\").datepicker because that's the decision one. If you cna explain more will help full

because in your script you have mentioned it have to be as
 $( "#datepicker" ).datepicker({

Where as in code behind implementation client Id of the page is used
"$('" + "#" + this.ClientID + "').datepicker('" +
0
 
LVL 8

Author Comment

by:PeteEngineer
ID: 37719580
I cannot post the error since it is visible

But i need to get the above posted javascript without images folder


i dont want to be like this : ( "#datepicker" ).datepicker({

instead i want to be like this :  $('" + "#" + this.ClientID + "').datepicker('" +
0
 
LVL 15

Expert Comment

by:santhimurthyd
ID: 37719808
ok, But could you give more inputs because this.ClientID will always retun the page id
"__Page" , not the "datePicker". so if you can use the control id instead of "this" will create the client id of the control to which the datepicker to be show.

If i'm correct you may mapped the event to button, In that case use the Button Id not this.
0
 
LVL 8

Author Closing Comment

by:PeteEngineer
ID: 37723880
Thanks
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Hidden Field Value 10 37
Showdialog 8 21
JavaScript Scope issue 4 20
Closing all open child forms. 4 24
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now