Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 22nd, 2008, 04:03 AM
Authorized User
 
Join Date: Aug 2008
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.

 
Old September 22nd, 2008, 04:16 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 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.
 
Old September 22nd, 2008, 10:28 AM
Authorized User
 
Join Date: Aug 2008
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.

 
Old September 22nd, 2008, 12:02 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 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.
 
Old September 23rd, 2008, 03:50 AM
Authorized User
 
Join Date: Aug 2008
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.

 
Old September 23rd, 2008, 06:15 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 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.
 
Old September 23rd, 2008, 08:30 AM
Authorized User
 
Join Date: Aug 2008
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.

 
Old September 23rd, 2008, 10:52 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 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.
 
Old September 24th, 2008, 02:38 AM
Authorized User
 
Join Date: Aug 2008
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.

 
Old September 24th, 2008, 04:26 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 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.





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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.