Solved

Passing Arguments to ASP.net UpdatePanel using __doPostBack()

Posted on 2009-07-03
3
6,238 Views
Last Modified: 2012-05-07
Hello,

I have an asp.net page that contains an update panel and I am trying to figure out how to pass arguments on it when I call __doPostBack().  I have the following function in my javascript that causes the UpdatePanel to perform an Async Postback and refresh itself:

        function UpdateFoodLogPanel() {
            __doPostBack('<%=FoodLogUpdatePanel.ClientID %>', GetSelectedDate());    
        }

This function is called everytime a user selects a new date from a Datepicker control on the page.  Obviously the second parameter of the __doPostBack() is the date which the user has selected.  I need to access this date in the code behind in order to populate the update panel with specific data based on what date has been passed.

In my codebehind I have tried using Request.Params("__EVENTARGUMENT") retrieve the date from the __doPostBack() yet for some reason it is always showing up as a blank string.  The funny thing is that I am using Firefox with Firebug and I am able to access the POST of the response and it is showing that __EVENTARGUMENT does have the proper date inside of it when it is passed.  Another curious thing going on is that the Page_Load event in the codebehind never seems to register IsPostBack as being true, even though the page IS being posted back when the UpdatePanel is refreshed.

If anyone could help me figure out how to get the date in the code behind it would be VERY much appreciated.

Thanks,

Mike
0
Comment
Question by:MClarkCCR
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 8

Expert Comment

by:MrAgile
ID: 24776599
Hi There,

Can you post a link to the page so I can take a look at it? Oh and the page won't register the IsPostBack  property as it's not performing one.

Sean
0
 
LVL 20

Expert Comment

by:ddayx10
ID: 24820575
Try it like this:

string eTarget = Request.Params.Get("__EVENTTARGET");
string eArg = Request.Params.Get("__EVENTARGUMENT");

That's C# but it works the same in VB pretty much.
0
 
LVL 3

Accepted Solution

by:
MClarkCCR earned 0 total points
ID: 24870723
Hello,

Thanks for your responses.  I apologize for the delay in getting back to this question, but I got bogged down with work from several other projects.  

I was actually able to find a solution by switching to a Telerik RadAjaxPanel as opposed to an UpdatePanel.  For those of you that don't know, it's basically Telerik's version of an UpdatePanel but with a more streamlined server and client-side API for working with ajax requests.  

I was able to initiate an AJAX postback manually via my JS code and pass the date as a parameter.  Then I was able to get the value very easily in the server side event.

dday10x:

For some reason those parameters were always registering as "" which was causing my code to fail.  It's strange because when I view the POST through Firebug I would see values for both of those __EVENT variables and they would be the proper ones I expected it to.  It was just impossible to get the values using Request.Params in the server-side.  I'm sure that is in part due to a misunderstanding on my end in regards to the ASP.net lifecycle and how the server treats AJAX-Postback request.  As MrAgile noted, the server doesn't register those request as a postback at all.

Oh well, thanks again for your responses.

Mike
0

Featured Post

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developer portfolios can be a bit of an enigma—how do you present yourself to employers without burying them in lines of code?  A modern portfolio is more than just work samples, it’s also a statement of how you work.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

734 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