RegisterOnSubmitStatement after client-side validation

后端 未结 2 1381
闹比i
闹比i 2021-02-19 07:24

I need to insert a bit of Javascript into the process when a Web Form is submitted, but after the client side validation takes place.

RegisterOnSubmitStatement seems to

相关标签:
2条回答
  • 2021-02-19 08:08

    After some research online and playing around with it, I figured out that you can do it by hooking into the Page's SaveStateComplete event. I guess the validation submit statement is registered during the PreRender event, so if you register it after that (in the SaveStateComplete event) you can get it afterward.

    You do have to re-register it, but that's not a big deal because I'm not relying on ViewState for my JS.

    0 讨论(0)
  • 2021-02-19 08:14

    that´s right, the RegisterOnSubmitStatement DO NOT WORK in the init function. It should be called after in the page lige cycle. I thing the right place therefor is:

    "PreRenderComplete"

    protected override OnInit(EventArgs e) 
    { 
       Page.PreRenderComplete+= new EventHandler(Page_PreRenderComplete); 
       base.OnInit(e); 
    } 
    
    void Page_PreRenderComplete(object sender, EventArgs e) 
    { 
       Page.ClientScript.RegisterOnSubmitStatement(typeof(Page), "name", "JS code here"); 
    }
    
    0 讨论(0)
提交回复
热议问题