如何避免按钮单击时的Page_Load()? [英] How to avoid Page_Load() on button click?

查看:59
本文介绍了如何避免按钮单击时的Page_Load()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个按钮,预览和保存.借助预览按钮,用户可以根据格式查看数据,然后可以保存.

I have two buttons, preview and Save. With help of preview button user can view the data based on the format and then can save.

但是,当单击预览时,附加到ajaxcontrol(Calender)的一个文本框将变为空,并且用户必须在保存之前填写日期.如何处理呢?预览时,单击我可获得详细信息以在布局中显示数据.

But when preview is clicked, one textbox attached to ajaxcontrol (Calender) becomes empty and user have to fill the date before saving. How to handle this? On preview click i get the details to show the data in layout.

<asp:TextBox ID="txtDate" ReadOnly="true" runat="server"></asp:TextBox>
                    <div style="float: right;">
                        <asp:ImageButton ID="imgcalender1" runat="server" ImageUrl="~/images/calendar.png"
                            ImageAlign="Bottom" />
                        <asp:CalendarExtender ID="ajCal" TargetControlID="txtpublishDate" PopupButtonID="imgcalender1"
                            runat="server">
                        </asp:CalendarExtender>
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator2"  ValidationGroup="group1" runat="server" ControlToValidate="txtDate"
                            ForeColor="Red" Font-Bold="true" ErrorMessage="*"></asp:RequiredFieldValidator>
                    </div>

<asp:Button ID="btnPreview" runat="server" Text="Preview" OnClick="btnPreview_Click" />
                    <asp:Button ID="btnsubmit" runat="server" ValidationGroup="group1" Text="Save" OnClick="btnsubmit_Click" />

推荐答案

根据我的理解,预览按钮导致回发,而您不希望这样做,请在预览按钮上尝试以下操作:

From what I am understanding the preview button is causing a postback and you do not want that, try this on your preview button:

<asp:button runat="server".... OnClientClick="return false;" />

同样也可以:

YourButton.Attributes.Add("onclick", return false");

用户问题的答案似乎是对预览按钮的HTML标记进行了简单的更改

it seems the answer to the user's question was simple change in the HTML mark up of the preview button

CausesValidation="False"

这篇关于如何避免按钮单击时的Page_Load()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆