postback

Which control caused the postback?

耗尽温柔 提交于 2019-11-27 08:34:14
I have two buttons: <asp:Button ID="Button1" runat="server" Text="Button" /> <asp:Button ID="Button2" runat="server" Text="Button" /> How can I determine on pageLoad which one of this two caused the postback? Is there a short solution as I know there are only two controls that can cause this postback? You can use this method to get the control that caused the postback: /// <summary> /// Retrieves the control that caused the postback. /// </summary> /// <param name="page"></param> /// <returns></returns> private Control GetControlThatCausedPostBack(Page page) { //initialize a control and set it

Can I create an ASP.NET ImageButton that doesn't postback?

て烟熏妆下的殇ゞ 提交于 2019-11-27 07:44:55
问题 I'm trying to use the ImageButton control for client-side script execution only. I can specify the client-side script to execute using the OnClientClick property, but how do I stop it from trying to post every time the user clicks it? There is no reason to post when this button is clicked. I've set CausesValidation to False, but this doesn't stop it from posting. 回答1: Here's one way you could do it without conflicting with the postback functioning of other controls: Define your button

asp.net issue with F5 after postback, because it does what it should

天大地大妈咪最大 提交于 2019-11-27 07:11:15
问题 I have a web form with a detail and a list view on it, the user fills the data in the fields of the detail view and then presses the "save" button, and everything is ok for the moment. However, if they press F5 after this operation a new record is going to be inserted in the DB, because the postback is repeated. Does anybody knows how this could be avoided? 回答1: This will be the same for any webpage that uses a POST request for its operations. You could stop this by using Response.Redirect(

How to maintain the value of label after postback in Asp.net? [closed]

为君一笑 提交于 2019-11-27 07:07:41
问题 In asp.net page I need to know how to maintain the value of a particular label assign by the html button click. After postback done. Detailed code: <table> <tr> <td><asp:Label ID="lbl1" runat="server" ClientIDMode="Static">Before Changing</asp:Label></td> <td><asp:Label id="lbl2" runat="server" ClientIDMode="Static"></asp:Label></td> <td><asp:TextBox ID="txtbox" runat="server"></asp:TextBox></td> </tr> <tr> <td><asp:Button ID="btnasp" runat="server" Text="ASP Button" Height="50px" Width=

Why doesn't returning false from OnClientClick cancel the postback

放肆的年华 提交于 2019-11-27 06:53:27
问题 I have a LinkButton where I use the OnClientClick property to ask the user whether he really wants to perform an action, e.g: <script> function confirmDelete() { return confirm('Do you really want to delete?'); } </script> <asp:LinkButton runat="server" OnClientClick="return confirmDelete()" ... /> This pattern usually works, but on this specific page, it doesn't. No matter whether I click OK or Cancel in the confirm dialog, the postback is executed. Just for completeness (to answer pst's

Force ASP.NET to generate JavaScript for all User Agents

半腔热情 提交于 2019-11-27 06:51:25
问题 I noticed recently in my ASP.NET web application that if I set my User Agent to an empty string (using a FireFox plug-in to spoof the user agent), then ASP.NET will not generate the javascript required to perform postbacks. More specifically, if you try calling the __doPostBack(a, b) function from your javascript, you will get an error saying that function is undefined. I understand that every browser has a user agent, so this won't come up that often, but the essence of the problem still

How to keep the Text of a Read only TextBox after PostBack()?

[亡魂溺海] 提交于 2019-11-27 05:33:15
问题 I have an ASP.NET TextBox and I want it to be ReadOnly . (The user modify it using another control) But when there is a PostBack() , The text get reset to an empty string. I understand that if you set the ReadOnly property to True of a TextBox it's content does not get saved through PostBack() . Is there a way to keep the content after PostBack() and make the TextBox not editable by the user? I tried to set the Enabled property to False ,But still the content doesn't save after PostBack() .

Implementation of IsPostBack in page load

馋奶兔 提交于 2019-11-27 04:32:54
问题 The more I use ASP.NET, the more if (!IsPostBack) {} seems pointless... First example: For example, I just Googled an issue, they said use this as part of the solution: if (!Page.IsPostBack) { Page.LoadComplete += new EventHandler(Page_LoadComplete); } Which does exactly as coded, LoadComplete will only fire on the first load. After clicking a button, or anything that triggers a postback, the LoadComplete event is left unhooked, thus skipping the event handler. Therefore, their "fix" only

Is it possible to disable f:event type=“preRenderView” listener on postback?

。_饼干妹妹 提交于 2019-11-27 04:32:49
Is it possible to "disable" triggering of this action when doing postback? <f:metadata> <f:event listener="#{defaultNewQuestionHandler.init}" type="preRenderView" /> </f:metadata> That's not possible with <f:event> . You need to manually check FacesContext#isPostback() inside the listener method. public void init() { if (!FacesContext.getCurrentInstance().isPostback()) { // ... } } In the upcoming JSF 2.2 <f:viewAction> tag, which is supposed to replace this <f:event type="preRenderView"> "workaround", it will however be possible with the onPostback attribute: <f:viewAction action="#

A potentially dangerous Request.Form value was detected from the client

拈花ヽ惹草 提交于 2019-11-27 04:14:11
I have this issue. I have tried everything. ValidateRequest="false".. and decoding and encoding html.. etc. etc.. What I need is a popup box (so im using ModalPopupExtender) to present to a user where people can type in xml settings and click ok/cancel button to close the popup and save. However i keep on getting this error "A potentially dangerous Request.Form value was detected from the client".. Here is my test code below (quick example of my scenario and error).. <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" ValidateRequest=