does asp.net provide a solution to post back from javascript to raise an server-side event in the pa

T

The Crow

i want to raise an event on the server with a javascript call on the client.
i found a solution but i think its not so elegant. the solution is:
i call __doPostBack("RefreshPage", ""); from javascript and check in the
Page_Load routine :
bool refreshPage = Request.Form["__EVENTTARGET"] == "RefreshPage";

i could do it with __doPostBack("", "RefreshPage"); and ["__EVENTARGUMENT"]
== "RefreshPage"

i could also add a hidden input control to the form, and set its value to
something and check its value in the Page_Load event handler..

i also tried
Page.GetPostBackEventReference(this, "RefreshPage");

it writes out : __doPostBack("", "RefreshPage");

i called that function in javascript to cause an postback and in the page i
overrode the RaisePostBackEvent method:



protected override void RaisePostBackEvent(IPostBackEventHandler
sourceControl, string eventArgument)

{

if(eventArgument == "RefreshPage")

{

//Do something..

}

base.RaisePostBackEvent (sourceControl, eventArgument);

}



but this method doesnt be called by the asp.net..

it is suprising that no elegant solution is provided by microsoft. does
anybody know better way doing this?
 
G

Guest

It's not that it's MS "not providing an elegant solution", its just that you
are dealing with apples and oranges....
Anyway, you're really pretty much on the right track. You'll have to force
the page to do a postback and catch some variable/value and manually fire
your event.
 
T

The Crow

i cant see apples and oranges around what do you mean? and why
raisepostbackevent doesnt raise? if it wont raise, why Page class expose
that method? i know it raises when for example i inherit from button, i
expect same thing when i inherit from page, because its a control too.
 
Joined
Jan 30, 2008
Messages
1
Reaction score
0
Solution?

So, were you able to find a solution. I am running into the same issue where I can manually examine the Form collection for __EVENTTARGET & __EVENTARGUMENT & go from there. But I cannot get the RaisePostBackEvent to fire even after the fact that I call RegisterForEventValidation for that control/argument.
 
Joined
Dec 4, 2007
Messages
16
Reaction score
0
I have dealt with posting back through a force postback. I am however unsure what your question is. If it is posting back, then you can catch the specific call on the page load checking the eventarget.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,740
Latest member
AdolphBig6

Latest Threads

Top