Solved

Passing Arguments to ASP.net UpdatePanel using __doPostBack()

Posted on 2009-07-03
3
6,217 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
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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

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.
Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

828 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