Solved

Passing Arguments to ASP.net UpdatePanel using __doPostBack()

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Problem to Popup 2 47
Remove right text widget from smaller screens 15 39
DLL in ASP.NET 20 38
modify h2 4 8
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Any business that wants to seriously grow needs to keep the needs and desires of an international audience of their websites in mind. Making a website friendly to international users isn’t prohibitively expensive and can provide an incredible return…
This video teaches users how to migrate an existing Wordpress website to a new domain.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

728 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

10 Experts available now in Live!

Get 1:1 Help Now