postback

user control event handler lost on postback

风流意气都作罢 提交于 2019-12-05 17:37:48
I have a menu usercontrol called LeftMenu that has a bulletedlist of linkitems. It's on the ascx page as such: <asp:BulletedList ID="PublisherList" DisplayMode="LinkButton" OnClick="PublisherList_Click" cssClass="Menu" runat="server"></asp:BulletedList> I databind the list in the page_load under if(!isPostBack) I'm having an issue on a page that loads the control. When the page first loads, the event handler fires. However, when the page posts back it no longer fires and in IE8, when I'm debugging, I get "Microsoft JScript runtime error: Object expected" in Visual Studio pointing at "_

ASP.NET postbacks lose the hash in the URL

心已入冬 提交于 2019-12-05 17:29:01
问题 On an ASP.NET page with a tabstrip, I'm using the hash code in the URL to keep track of what tab I'm on (using the BBQ jQuery plugin). For example: http://mysite.com/foo/home#tab=budget Unfortunately, I've just realized that there are a couple of places on the page where I'm using an old-fashioned ASP.NET postback to do stuff, and when the postback is complete, the hash is gone: http://mysite.com/foo/home ... so I'm whisked away to a different tab. No good. This is a webforms site (not MVC)

ASP.NET hidden field not updating after postback

余生长醉 提交于 2019-12-05 16:50:59
I have some code on my ASP page which looks like this: <asp:UpdatePanel runat="server" id="updatepanel1" UpdateMode="Conditional" onload="updatepanel1_Load" ChildrenAsTriggers="false"> <ContentTemplate> <asp:HiddenField id="sendingRequest" runat="server" Value="0" /> .... </ContentTemplate> </asp:UpdatePanel> I also have some javascript on my page which does this, to trigger the update of the updatepanel: var sendingRequest = document.getElementById("<%=sendingRequest.ClientID%>"); sendingRequest.value = "1"; __doPostBack('<%= updatepanel1.ClientID %>', ''); Everything works fine up to now,

ASP.NET Client to Server communication

最后都变了- 提交于 2019-12-05 13:35:52
Can you help me make sense of all the different ways to communicate from browser to client in ASP.NET? I have made this a community wiki so feel free to edit my post to improve it. Specifically, I'm trying to understand in which scenario to use each one by listing how each works. I'm a little fuzzy on UpdatePanel vs CallBack (with ViewState): I know UpdatePanel always returns HTML while CallBack can return JSON. Any other major differences? ...and CallBack (without ViewState) vs WebMethod. CallBack goes through most of the Page lifecycle, WebMethod doesn't. Any other major differences?

How to hide and display asp:buttons in asp.net from code behind?

馋奶兔 提交于 2019-12-05 10:57:21
I am working on asp.net web application. In one Page I have two asp buttons. I want to display them in one condition otherwise I don't want to display them. So I'm trying to do the same like this. But Its not working. I can't find the reason behind it. Please tell me where is the issue. To Hide Buttons if (!IsPostBack) { ButtonReplaceId.Style.Add("display", "none"); ButtonAssociateRules.Style.Add("display", "none"); } To display buttons protected void ApplyAssociation(object sender, EventArgs e) { //Some piece of code if(a==0) { ButtonAssociateRules.Style.Add("display", "block");

A secure implementation of Page.IsPostBack?

别来无恙 提交于 2019-12-05 10:46:18
Following my previous question as to whether ASP.net's default Page.IsPostBack implementation is secure (it's not; it can be faked... the HTTP verb doesn't even have to be POST!), I was thinking; surely there must be a better way to implement it? Can we come up with a Page.IsPostBack implementation which, when it is true, is almost guaranteed to indicate that the page is an actual ASP.net postback? This is important if one wants to do security checking only once (like whether some content is going to appear, based on the user's role(s)), and wants to do it only if we're NOT dealing with an ASP

ASP.NET determine which button was clicked inside an updatepanel in page load event

柔情痞子 提交于 2019-12-05 10:13:34
I'm trying to get my head around a page lifecycle issue of an ASP.NET UserControl. What I have is an updatepanel with two buttons in it. Now, in the Page_Load event I need to make a check to see which of the two buttons was clicked. I do know that I should use the click event for this, but this is a case of quite a complex page cycle with dynamically added controls and so on, so forth, so that is not an option, unfortunately :-( I've tried to check on the Request.Form["__EVENTTARGET"] value, but since the buttons are inside an UpdatePanel the value is an empty string (at least I guess that's

ASP.net with C# Keeping a List on postback

前提是你 提交于 2019-12-05 06:01:33
My situation goes like this: I have these lists with data inserted into them when a user presses an ADD button, but I guess on postback the Lists are re-zeroed. How do you keep them preserved? I've been looking for the answer, but I guess I don't quite understand how to use the session, etc. I'm very new to ASP.net and not much better with C# it would seem. public partial class Main : System.Web.UI.Page { List<string> code = new List<string>(); protected void Page_Load(object sender, EventArgs e) { //bleh } protected void cmdAdd_Click(object sender, EventArgs e) { code.Add(lstCode.Text); }

ASP.NET custom control: when is LoadPostData() called?

我们两清 提交于 2019-12-05 04:48:38
I have developed a custom control that extends ListBox. The idea is that the control 'remembers' modifications to its elements which occurred client-side, e.g. as a result of an AJAX request. The way it works is that the control also renders a hidden input, and the result of the AJAX request is stored in the hidden input. This is posted back, and the control's LoadPostData() method looks for the hidden input, and if the hidden input has data, creates the ListItem collection from it. This works perfectly so long as the user has made a selection from the list box . If they have not, the

ASP.NET private member field loses value on postback

北慕城南 提交于 2019-12-05 03:58:41
Consider the following code: public partial class TeacherControlPanel : System.Web.UI.Page { protected string username = string.Empty; protected void Page_Load(object sender, EventArgs e) { username = (string)Request.QueryString["username"]; Ice_Web_Portal.BO.Teacher teacher = Ice_Web_Portal.BO.Teacher.GetTeacherByUsername(username); if (teacher != null) { labUsername.Text = username; labName.Text = teacher.TeacherName; labTeacherCode.Text = teacher.TeacherCode; Dept dept = teacher.Department; if (dept != null) { labDepartment.Text = dept.DeptName; } } else { //labErrorMessage.Text = "No