1

I have an ASP page with an asp:DropDownList (with AutoPostBack="true") so that when the user changes it, it reload the appropriate data.

Under that control i have a list of UserControls, that includes a tinymce editor (tied to an asp:TextBox) and an asp:ImageButton to save the data.

When clicking on the ImageButton, the applications send the postback data via ajax to the same page (__EVENTARGUMENT, __EVENTTARGET, etc...). Why does it load that ajax page, and how do i prevent it? I'm updating the value in the DB in the OnClick event handler on the ImageButton, so all I need to do, is get ride of that ajax call.

Any ideas?

4

2 回答 2

0

您没有声明您正在使用 UpdatePanel,但这大概是您实现 ajax 调用的方式。如果是这样,您需要添加一个触发器以从 ajax 中排除 imagebutton 事件:

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional"> 
<Triggers> 
<asp:PostBackTrigger ControlID="ImageButton" />
</Triggers>
<ContentTemplate> </ContentTemplate> 
</asp:UpdatePanel> 
于 2011-02-22T12:44:40.983 回答
0

解决方案 1

<asp:ImageButton ID="btn" runat="server" ImageUrl="~/images/yourimage.jpg"
OnClientClick="return false;"  />

或解决方案 2

<asp:ImageButton ID="btn" runat="server" ImageUrl="~/images/yourimage.jpg" 
OnClientClick="yourmethod(); return false;"  />

另外(解决方案2),你的javascript方法可能是这种形式

<script type="text/javascript">
    function yourmethod() {
    __doPostBack (__EVENTTARGET,__EVENTARGUMENT); //for example __doPostBack ('idValue',3);
    }
</script>

在后面的代码中

protected void Page_Load(object sender, System.EventArgs e)
{
    if (this.IsPostBack) {
        string eventTarget = this.Request("__EVENTTARGET") == null ? string.Empty : this.Request("__EVENTTARGET");
        string eventArgument = this.Request("__EVENTARGUMENT") == null ? string.Empty : this.Request("__EVENTARGUMENT");
    }
}
于 2013-06-21T10:08:14.263 回答