Which control caused the 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 to null Control ctrl = null; //get the event target name and find the … Read more

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

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=”#{defaultNewQuestionHandler.init}” onPostback=”false” /> … Read more

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

Use <httpRuntime requestValidationMode=”2.0″ /> in your web.config (keeping any attributes you already have on that element, if it’s already there). ASP.NET4.0 ignores ValidateRequest otherwise. And, of course, do make sure that you take necessary measures to protect against genuinely dangerous requests, now that it’s not being done for you. Edit: A great way of doing … Read more

Maintain Panel Scroll Position On Partial Postback ASP.NET

There is no built-in facility to resolve it in asp.net However, there is a workaround for this problem; You need to handle it with javascript. Solution is mentioned here: Maintain Scrollbar Position Inside UpdatePanel After Partial PostBack Edited 20-May-2012; after seeing the comments <form id=”form1″ runat=”server”> <asp:ScriptManager ID=”ScriptManager1″ runat=”server” ScriptMode=”Release” /> <script type=”text/javascript”> // It … Read more

ListItems attributes in a DropDownList are lost on postback?

I had the same problem and wanted to contribute this resource where the author created an inherited ListItem Consumer to persist attributes to ViewState. Hopefully it will save someone the time I wasted until I stumbled on it. protected override object SaveViewState() { // create object array for Item count + 1 object[] allStates = … Read more

What is a postback?

The following is aimed at beginners to ASP.Net… When does it happen? A postback originates from the client browser. Usually one of the controls on the page will be manipulated by the user (a button clicked or dropdown changed, etc), and this control will initiate a postback. The state of this control, plus all other … Read more

@ViewScoped bean recreated on every postback request when using JSF 2.2

This, import javax.faces.view.ViewScoped; is the JSF 2.2-introduced CDI-specific annotation, intented to be used in combination with CDI-specific bean management annotation @Named. However, you’re using the JSF-specific bean management annotation @ManagedBean. import javax.faces.bean.ManagedBean; You should then be using any of the scopes provided by the very same javax.faces.bean package instead. The right @ViewScoped is over there: … Read more

OnclientClick and OnClick is not working at the same time?

From this article on web.archive.org : The trick is to use the OnClientClick and UseSubmitBehavior properties of the button control. There are other methods, involving code on the server side to add attributes, but I think the simplicity of doing it this way is much more attractive: <asp:Button runat=”server” ID=”BtnSubmit” OnClientClick=”this.disabled = true; this.value=”Submitting…”;” UseSubmitBehavior=”false” … Read more

ASP.NET postback with JavaScript

Here is a complete solution Entire form tag of the asp.net page <form id=”form1″ runat=”server”> <asp:LinkButton ID=”LinkButton1″ runat=”server” /> <%– included to force __doPostBack javascript function to be rendered –%> <input type=”button” id=”Button45″ name=”Button45″ onclick=”javascript:__doPostBack(‘ButtonA’,”)” value=”clicking this will run ButtonA.Click Event Handler” /><br /><br /> <input type=”button” id=”Button46″ name=”Button46″ onclick=”javascript:__doPostBack(‘ButtonB’,”)” value=”clicking this will run ButtonB.Click … Read more