Results 1 to 6 of 6

Thread: duel onclick client and server..?[RESOLVED]

  1. #1

    Thread Starter
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267

    Cool duel onclick client and server..?[RESOLVED]

    I want to have a client side script fire and then have postback fire

    can anyone tell me about do_postback?

    I want to fire a System.Web.UI.WebControls.Button Click event from a javascript click event.
    Last edited by Magiaus; Jun 5th, 2004 at 10:12 PM.
    Magiaus

    If I helped give me some points.

  2. #2
    Frenzied Member Fishcake's Avatar
    Join Date
    Feb 2001
    Location
    Derby, UK
    Posts
    1,092
    i dabbled with this for a bit but the best i managed was causing a postback that made page_load get called but not the code for a button. I settled for just adding an onclick event for the button like
    VB Code:
    1. Me.btnCalculateScores.Attributes.Add("onclick", "return confirm('..... If you are sure you wish to continue click OK else click CANCEL');")
    which just adds a javascript confirm box. I suppose it might depend on how complicated the javascript was though as to wether this is a suitable method for you.

  3. #3

    Thread Starter
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267
    I don't know yet. This is a fluff feature and I haven't got to it yet. I'll let you guys know what I come up with tough. I had seen article awhile back maybe I can find it again.....
    Magiaus

    If I helped give me some points.

  4. #4

    Thread Starter
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267
    to fire a button click event from client script

    Code:
    __doPostBack('btn_id','');
    I just added this to my Base.Page class


    Code:
    		protected override void OnLoad(System.EventArgs e)
    		{
    			if(Request["__EVENTTARGET"] == "PostBackCommand" && Request["__EVENTARGUMENT"] != null && IsPostBack)
    			{
    				PostBackCommand(Request["__EVENTARGUMENT"]);
    			}
    		}
    		/// <summary>
    		/// Overide this member to add handling of Commands 
    		/// raised from client script using __doPostBack(eventTarget, eventArgument).
    		/// </summary>
    		/// <param name="command">The command to execute.</param>
    		protected virtual void PostBackCommand(string command){}
    you overide PostBackCommand and use a select case/switch statement to act on diffrent commands bassed on the command string.

    javascript to run a command from client/cause post back and proccess any PostBack Commands.
    Code:
    __doPostBack('PostBackCommand', 'command_name');
    So using this system you would use a normal none server button with
    Code:
    onclick="clientScriptFunction()"
    in the client script you then do what you need to with the client and then to prefom you server operation you call
    Code:
    __doPostBack('PostBackCommand','ButtonClick');
    I think this can be very usefull. What do you guys say?
    Magiaus

    If I helped give me some points.

  5. #5
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    Great information. I never knew that was there. I don't use much javascript right now, but I can see a use for this.

    Thanks.

  6. #6

    Thread Starter
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267

    Re: duel onclick client and server..?[RESOLVED]

    Magiaus

    If I helped give me some points.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width