admin管理员组文章数量:1287649
I wish to call a method in my code behind from JavaScript, I sort of know how to do it.. I must call __DoPostBack
passing name of control and parameters..
But what if an event doesn't exist i.e. NO CONTROL. Really what i am trying to do is call an event.. but the event doesn't exist as there is no control associated with it..
I sort of could do this:
If IsPostBack Then
If Request(”__EVENTTARGET”).Trim() = “CleanMe” Then
CleanMe()
End If
.....
But this means I must do it manually. Can I not wire up an event.... otherwise I will have loads of different IFs (i.e. If this passed then call this .. etc..).
Any ideas?
Thanks
I wish to call a method in my code behind from JavaScript, I sort of know how to do it.. I must call __DoPostBack
passing name of control and parameters..
But what if an event doesn't exist i.e. NO CONTROL. Really what i am trying to do is call an event.. but the event doesn't exist as there is no control associated with it..
I sort of could do this:
If IsPostBack Then
If Request(”__EVENTTARGET”).Trim() = “CleanMe” Then
CleanMe()
End If
.....
But this means I must do it manually. Can I not wire up an event.... otherwise I will have loads of different IFs (i.e. If this passed then call this .. etc..).
Any ideas?
Thanks
Share Improve this question edited Apr 15, 2009 at 13:57 Dan Lew 87.4k33 gold badges184 silver badges176 bronze badges asked Apr 15, 2009 at 13:54 mark smithmark smith 20.9k47 gold badges136 silver badges190 bronze badges3 Answers
Reset to default 2You may be able to use a PageMethod to call your codebehind function, here is a link to an example: http://blogs.microsoft.co.il/blogs/gilf/archive/2008/10/04/asp-net-ajax-pagemethods.aspx
If you want to use __doPostBack(), you must have a control to receive the mand. However, you don't have to explicitly wire up an event to handle it. If you want the __doPostBack() to invoke, say, Foo(), do the following:
MyControl : IPostBackEventHandler
{
void RaisePostBackEvent(string eventArgument)
{
Foo();
}
}
Calling __doPostBack() will invoke the RaisePostBackEvent method on the targeted control.
If you realy want to wire up to an event, the option that will give you less trouble is to create a hidden asp button and click it via javascript
本文标签: aspnetdoPostbackcalling code behind events from JavaScriptStack Overflow
版权声明:本文标题:asp.net - __doPostback - calling code behind events from JavaScript? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741318177a2372044.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论