Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Ajax
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Ajax the combination of XHTML, CSS, DOM, XML, XSLT, XMLHttpRequest, and JavaScript
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Ajax section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old September 22nd, 2008, 05:03 AM
Authorized User
 
Join Date: Aug 2008
Location: , , .
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Default UpdatePanel

Hello.
I have some Updatepanel's in my .aspx page and some code behind for the communication with the server. I send some id's to the server and I receive and xml file and a thumbnail. I click the thumb and I open the large image. When I open the large image I need to pass some values to my javascript functions, to make some client-side work. This thing happens at the second click on the page.
At first the page loads and the variables are 0(the variables are public in c#). I make the request for the thumb, I click the thumb and I have to pass the values(for some zoom and pan).
Every asp component is in a different updatepanel.
I use Asp .Net 3.5 with c# 3.0 in VS 2008.
Thank you.

Reply With Quote
  #2 (permalink)  
Old September 22nd, 2008, 05:16 AM
Imar's Avatar
Wrox Author
Points: 71,164, Level: 100
Points: 71,164, Level: 100 Points: 71,164, Level: 100 Points: 71,164, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 16,960
Thanks: 79
Thanked 1,559 Times in 1,536 Posts
Default

Hi Daniel,

A typical question on a forum ends with a ? so you can see what the question is. In your case, I couldn't find any. This makes it impossible to understand what you are asking or what you need help with.

Imar

---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.
Reply With Quote
  #3 (permalink)  
Old September 22nd, 2008, 11:28 AM
Authorized User
 
Join Date: Aug 2008
Location: , , .
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well my problem is that only on Page_Load event my variables values are passed in javascript, and when I click the thumb my function that sends the values to javascript doesn't do anything.
My question is how do I send C# variables values to javascript after the page is loaded, and I have to do partial post back because I have my components in updatepanels.
This is a piece of code:
C#:
        public string jszoom_factor = string.Empty;
        public string jsmyX = string.Empty;
        public string jsmyY = string.Empty;
        public string jssessionId = string.Empty;
        public string jsmyId = string.Empty;
//This is the function that sends the values
public void ClientSideValidationFlag(bool initJSVariable, int value)
        {
            if (initJSVariable == true)
            {
                jsmyId = myId.ToString();
                jszoom_factor = Zoom.my_Zoom.ToString();
                jsmyX = myX.ToString();
                jsmyY = myY.ToString();
                jssessionId = sessionID;
            }
            else
            {
                jsmyId = myId.ToString();
                jszoom_factor = Zoom.my_Zoom.ToString();
                jsmyX = myX.ToString();
                jsmyY = myY.ToString();
                jssessionId = sessionID;
            }
            ScriptManager.RegisterClientScriptBlock(myUpdateTh umb, typeof(UpdatePanel), "JsVariableValidationKey", jsmyId, true);
            ScriptManager.RegisterClientScriptBlock(myUpdateTh umb, typeof(UpdatePanel), "JsVariableValidationKey", jszoom_factor, true);
            ScriptManager.RegisterClientScriptBlock(myUpdateTh umb, typeof(UpdatePanel), "JsVariableValidationKey", jsmyX, true);
            ScriptManager.RegisterClientScriptBlock(myUpdateTh umb, typeof(UpdatePanel), "JsVariableValidationKey", jsmyY, true);
            ScriptManager.RegisterClientScriptBlock(myUpdateTh umb, typeof(UpdatePanel), "JsVariableValidationKey", jssessionId, true);
        }
javascript: This is how I receive them in javascript
var jsmyX = "<%=jsmyX%>";
var jsmyY = "<%=jsmyY%>";
var jszoom_factor = parseFloat("<%=jszoom_factor%>");
var jssessionId = "<%=jssessionId%>";
var jsmyId = "<%=jsmyId%>";

My thumbnails are in an updatepanel, my large image is in another updatepanel and the buttons are in a third updatepanel.
How to I send my values, on every thumb click?
Thank you.

Reply With Quote
  #4 (permalink)  
Old September 22nd, 2008, 01:02 PM
Imar's Avatar
Wrox Author
Points: 71,164, Level: 100
Points: 71,164, Level: 100 Points: 71,164, Level: 100 Points: 71,164, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 16,960
Thanks: 79
Thanked 1,559 Times in 1,536 Posts
Default

Now, that's a question... ;)

There may be other ways to do this as well, but one way to do this is using a Literal control and set its Text in Code Behind on PostBack to a JavaScript. Something like this (assuming myVar is declared elsewhere):
Code:
myLiteral.Text = "<script type=\"text/javascript\">myVar = 'SomeValue'; alert(myVar);</script>";
Just a simple example, but I hope it puts you on the right track.

Cheers,

Imar


---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.
Reply With Quote
  #5 (permalink)  
Old September 23rd, 2008, 04:50 AM
Authorized User
 
Join Date: Aug 2008
Location: , , .
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The problem is that I have to send my values from C# to Javascript after the Page_Load event. I guess is some method from ScriptManager that passes the values after this event but I haven't find it.
Thank you.

Reply With Quote
  #6 (permalink)  
Old September 23rd, 2008, 07:15 AM
Imar's Avatar
Wrox Author
Points: 71,164, Level: 100
Points: 71,164, Level: 100 Points: 71,164, Level: 100 Points: 71,164, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 16,960
Thanks: 79
Thanked 1,559 Times in 1,536 Posts
Default

Yes, but you can still do that. In fact, that was what my idea was all about.

How you trigger the code that fills the Literal depends on your needs. You could use a Button, or another control triggering a PostBack, like your own Thumb image.

Alternatively, you can create a PageMethod or access a web service to get the data.

Can you explain what exactly it is you want to do? Why won't setting a Literal as I described work for you?

Imar


---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.
Reply With Quote
  #7 (permalink)  
Old September 23rd, 2008, 09:30 AM
Authorized User
 
Join Date: Aug 2008
Location: , , .
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well the scenario is like this:
I have a server loaded with images, and I have a web page that makes a search on that server, and based on the search the server returns me some thumbnails. When I do the click on the thumbnail I have to make another request to that server for the large image and some details(name, date, resolution). After that I do some math to put the image fit to my asp image component. What I need to do is to pass my resolution, my image id, and the current zoom factor for that clicked image from C# to Javascript to do a zoom in/out and panning. All of my components are in Updatepanels because I need to refresh only pieces of page(like my image component). My problem is how do I pass the values if the code and components doesn't all make refresh?Because if I use public void ClientSideValidationFlag function in the thumb click event function it doesn't pass anything in Javascript, but if I call the same function(ClientSideValidationFlag ) in Page_Load it passes(I know that because I set to load the first from the server by default). Maybe it is another method besides this-RegisterClientScriptBlock, because with the debugger put on ClientSideValidationFlag in that thumb click event it doesn't move me the the javascript section to show me that he upgraded the variables like he does when the ClientSideValidationFlag is put in the Page_Load event.
Thank You.

Reply With Quote
  #8 (permalink)  
Old September 23rd, 2008, 11:52 AM
Imar's Avatar
Wrox Author
Points: 71,164, Level: 100
Points: 71,164, Level: 100 Points: 71,164, Level: 100 Points: 71,164, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 16,960
Thanks: 79
Thanked 1,559 Times in 1,536 Posts
Default

Did you look into the PageMethods I suggested?

http://www.singingeels.com/Articles/...PNET_AJAX.aspx

Imar


---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.
Reply With Quote
  #9 (permalink)  
Old September 24th, 2008, 03:38 AM
Authorized User
 
Join Date: Aug 2008
Location: , , .
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I think this is it. Only now I have another problem. My autocomplete from Visual Studio 2008 doesn't recognize my literals. This is an unusual problem. Do you know what to do?
Thank you.

Reply With Quote
  #10 (permalink)  
Old September 24th, 2008, 05:26 PM
Imar's Avatar
Wrox Author
Points: 71,164, Level: 100
Points: 71,164, Level: 100 Points: 71,164, Level: 100 Points: 71,164, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 16,960
Thanks: 79
Thanked 1,559 Times in 1,536 Posts
Default

Hi daniel,

Difficult to say without seeing any code. Where are they declared? Inside another container control so you may need to use FindControl?

Posting your code with questions like this makes answering them a lot easier...

Imar


---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with ajax updatepanel alexmalayil ASP.NET 2.0 Professional 0 October 18th, 2007 06:07 AM
UpdatePanel/ModalPopUp Postback Problem jlrolin ASP.NET 2.0 Professional 3 August 13th, 2007 02:23 PM
Prblem while using <asp:updatepanel> rajatake ASP.NET 2.0 Professional 5 March 22nd, 2007 03:05 PM
UpdatePanel Problem? rajatbirth_1978 .NET Framework 2.0 0 February 14th, 2007 02:27 AM



All times are GMT -4. The time now is 10:54 AM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.