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.
Printable View
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.
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 likewhich 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.VB Code:
Me.btnCalculateScores.Attributes.Add("onclick", "return confirm('..... If you are sure you wish to continue click OK else click CANCEL');")
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.....
to fire a button click event from client script
I just added this to my Base.Page classCode:__doPostBack('btn_id','');
you overide PostBackCommand and use a select case/switch statement to act on diffrent commands bassed on the command string.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){}
javascript to run a command from client/cause post back and proccess any PostBack Commands.So using this system you would use a normal none server button withCode:__doPostBack('PostBackCommand', 'command_name');
in the client script you then do what you need to with the client and then to prefom you server operation you callCode:onclick="clientScriptFunction()"
I think this can be very usefull. What do you guys say?Code:__doPostBack('PostBackCommand','ButtonClick');
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.
new better solution http://vbforums.com/showthread.php?t=329597