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

Discussion in 'ASP .Net' started by The Crow, Sep 8, 2005.

  1. The Crow

    The Crow Guest

    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?
     
    The Crow, Sep 8, 2005
    #1
    1. Advertisements

  2. RE: does asp.net provide a solution to post back from javascript to ra

    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.

    --
    Curt Christianson
    site: http://www.darkfalz.com
    blog: http://blog.darkfalz.com



    "The Crow" wrote:

    > 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?
    >
    >
    >
     
    =?Utf-8?B?Q3VydF9DIFtNVlBd?=, Sep 8, 2005
    #2
    1. Advertisements

  3. The Crow

    The Crow Guest

    Re: does asp.net provide a solution to post back from javascript to ra

    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.
     
    The Crow, Sep 8, 2005
    #3
  4. The Crow

    arifkhan1

    Joined:
    Jan 30, 2008
    Messages:
    1
    Likes Received:
    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.
     
    arifkhan1, Jan 30, 2008
    #4
  5. The Crow

    ProgTalk

    Joined:
    Dec 4, 2007
    Messages:
    16
    Likes Received:
    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.
     
    ProgTalk, Jan 31, 2008
    #5
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Oney
    Replies:
    2
    Views:
    4,656
    Natty Gur
    May 17, 2004
  2. sylvia sil
    Replies:
    1
    Views:
    844
    Curt_C [MVP]
    Dec 29, 2004
  3. Jose Walker
    Replies:
    0
    Views:
    889
    Jose Walker
    Jul 27, 2006
  4. Jacol

    raise or not to raise [Newbie]

    Jacol, Feb 3, 2007, in forum: Python
    Replies:
    5
    Views:
    655
    Gabriel Genellina
    Feb 5, 2007
  5. =?Utf-8?B?Z29yaWxsYQ==?=
    Replies:
    1
    Views:
    1,014
    Masudur
    May 25, 2007
  6. Ahmet Gunes
    Replies:
    1
    Views:
    695
    bruce barker
    Apr 10, 2008
  7. Aymer
    Replies:
    1
    Views:
    535
    Alvin Bruney
    Sep 19, 2003
  8. Guest

    Fire server side event before client side event

    Guest, Mar 17, 2005, in forum: ASP .Net Web Controls
    Replies:
    3
    Views:
    848
    Ken Cox [Microsoft MVP]
    Mar 18, 2005
Loading...