i'm trying to follow the suggestion here: Call ASP.NET function from JavaScript?
But it's not working for me. The page does post back. but my RaisePostBacKEvent
never fires. I am doing this in a usercontrol and not a page:
public partial class MyTreatment : System.Web.UI.UserControl, IPostBackEventHandler
Anyone have any suggestions on how to get this working?
Thanks
i'm trying to follow the suggestion here: Call ASP.NET function from JavaScript?
But it's not working for me. The page does post back. but my RaisePostBacKEvent
never fires. I am doing this in a usercontrol and not a page:
public partial class MyTreatment : System.Web.UI.UserControl, IPostBackEventHandler
Anyone have any suggestions on how to get this working?
Thanks
Share Improve this question edited May 23, 2017 at 12:08 CommunityBot 11 silver badge asked Sep 23, 2011 at 19:50 merkmerk 1,7415 gold badges23 silver badges40 bronze badges 1- Show us your __doPostBack call... – Brian Mains Commented Sep 23, 2011 at 19:58
2 Answers
Reset to default 5Are you specifying the ClientID of your control, as opposed to the ClientID of the page (as in the example from the other SO question you referenced)?
If not then that would explain why the page is posting back but not calling the RaisePostBack method in your control.
To reference the ClientID of your control, call the __doPostBack function like so:
__doPostBack("<%= yourControlID.ClientID %>", "an argument");
As a side note, if your control is the only control on the page then the __doPostBack function will not be created by ASP.NET unless you make a call to GetPostBackEventReference for your control.
You do not necessarily need to make use of the reference but you need to call the method so the page knows to generate the client side function.
You can call GetPostBackEventReference like so:
public class MyTreatment : UserControl, IPostBackEventHandler
{
protected override void OnLoad(EventArgs e)
{
string postBackEventReference = Page.ClientScript.GetPostBackEventReference(this, string.Empty);
base.OnLoad(e);
}
public void RaisePostBackEvent(string eventArgument)
{
}
}
Hope this helps.
It should work with using the user control instance ID's UniqueID property (I couldn't get this to work with ClientID, in my own personal experiences). Like so:
__doPostBack("<%= yourControlID.UniqueID %>", "arg");
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744796650a4594243.html
评论列表(0条)