I have links in a content panel which will fire when page is new/refreshed. But if you navigate throughout the page then hit the back button to go back to the main page, none of the linkbutton events in the content panel fire.
I am just kind of loss - what would cause this functionality. I can post code if needed but I really am just looking for suggestions as to where to start looking.
You should start with the asp page life cycle - to make sense of why the event you are expecting to fire hasn't.
Related
I hope I can explain this well without having to post scads of source.
I have a page in an online store that lets the user pick a date for a tour. That page has a ConLib which contains a couple of panels. The first is:
<asp:Panel ID="pnl_Grid" runat="server">
<cb:SortedGridView ID="VariantGrid" runat="server"
AutoGenerateColumns="False" Width="100%"
SkinID="PagedList" DataKeyNames="OptionList">
<Columns>
</Columns>
</cb:SortedGridView>
</asp:Panel>
and then another asp:Panel with other stuff - calendar, buttons, etc. The SortedGridView is supplied by our shopping cart provider and is basically a regular asp:Grid.
When the user says they want 3 tickets I do a
pnl_Grid.Enabled="false"
to keep them from changing it after picking a date/time. At various points they can click a reset button that will do many things but one task is to set the value to zero in the gridrow text boxes and enable the Grid since they reset the process and want to pick new things.
I have stepped through the code with breakpoints in place and it seems that the problem I am having is that my reset button click event handler fires after the Grid is rendered with the disabled status in the Page Render stage of life. If that is true then setting the Grid in code behind will never show the enabled grid on the page without a refresh since it's already rendered. If I refresh the page manually it does indeed show as enabled so I think I'm on the right problem.
My question is twofold, if there is enough info here to answer it:
1. Is it likely that what I think I am seeing is true - the page renders the control disabled and then the button handler tries to enable it but it's too late at that point since the control is already rendered?
2. How can I work around this? I would prefer to avoid JQuery if at all possible... it has some unintended side effects with the way our original store software is written.
Further info:
I have a status flag _EventSelected which tells if the calendar event has been selected. On the reset button click I set that to false and on PreRender I check that to see if it is false and enable the Grid. Again, the status doesn't change until the Reset Button Click event handler and that is after the PreRender.
Thanks for your input! I swear, some days ASP.NET makes perfect sense to me and other days it is clear as mud.
I found a working solution. To force the page to refresh after the button enables the Grid, which is not displayed without the refresh, I added this to the btn_Reset_Click handler, found by searching for "cause page reload":
Page.Response.Redirect(Page.Request.Url.ToString(), false);
It's not a bad solution since I'm in a reset / start-over state anyway. Thanks for taking time to read my question! Hopefully this will help someone else some day.
I'm very very new to asp.net, and in my tour of its features I found that if you use Server.Transfer instead of Response.Redirect then, among other things, you could preserve the URL of the original page. I created two test pages.
The first has a textbox and a button. When you click the button, the contents of the textbox are saved in the Session variable and Server.Transfer is used to load the second page. On this page there's a button and a label. When you click the button, the label gets populated with what was saved in the session variable.
The issue is, when I click the button on the second page and the label is altered, the URL changes to that of the second page. This seems a bit to defeat the purpose, so how do I go about preserving the URL?
Clicking the button on the second page is causing a postback and the server is showing the URL of the page you are posting back to (the second page). In effect, you have done a Response.Redirect to yourself.
I am curious as to why you want to have two separate .aspx pages behave as if they are only one. One of the major drawbacks of using Server.Transfer is the confusion it causes the user when they think they are on a new page, but the browser says otherwise; especially in bookmarking scenarios.
If you want the logic to reside in a single .aspx page, but act as two separate logical units, then I suggest you use ASP.NET Panel controls that show/hide the logic as needed and the page's code-behind can react to the necessary events (i.e. button clicks) all in one page and the URL will be the same the entire time.
I have a web page that prompts for user input via DropDownLists in some table cells. When a selection is made the selection replaces the DropDownList so that the action can only be performed once. In the case that a change needs to be made I want to be able to click a button that reloads the page from scratch. I have Googled and Googled but I have not managed to find a way to do this.
Any advice is appreciated.
Regards.
Put a link on the page with the text "Reload" and the url the url of the page. It's perfectly valid to have a page with a link to itself.
If you don't like the link idea, use a standard Button and in the click event, use Response.Redirect to redirect to the current page.
You can set an OnClick for your button that resets each DropDownList's SelectedIndex to 0 instead of reloading the page from scratch. Alternatively, you can set a Response.Redirect([the page's url]) into the OnClick as is suggested here.
I have an Ajax AsyncFileUpload on one of my pages (inside a update panel). The control works, however I want the page to reload after the upload is complete. I tried a Response.Redirect in the code behind for the OnUploadedComplete method and a location.reload(true) in the OnClientUploadComplete. Both result in javascript alert of `Server Response Error: 'Unknown Server error'
Do you want to see the response page?` and the page doesn't refresh.
Has anyone been able to do a full page refresh after the upload has completed?
Edit: I mistakenly said the AsyncFileUpload is in a control panel, I meant to say update panel.
Use asp:FileUpload control and register it as postback control with Scriptmanager's RegisterPostBackControl method. Or add postback trigger entry for this FileUpload to Triggers collection of UpdatePanel
This control panel that you told. Is this a UpdatePanel? If it is, you can try an upd.Update(); to refresh the panel.
Becareful, if you have Response on your backside you may be ending your page's life cycle right there. This is just a guess. Check to make sure that your code is even reaching the intended point. Look for things like Response.End which will will prevent anything thereafter from executing.
I need to populate 4 GridViews on an aspx page, but I only bind a datatable to one of them on page load. I need to pupulate the other 3 after page load.
does anyone know the best way to do this using ajax ?
Currently I'm using javascript to __doPostBack on a button that pupulates the 3 GridViews but unfortunately this forces a full page load even when using an update panel. I need the page to load, and then populate the GridViews as the datatables are returned.
any suggestions would be much apreciated.
The way you are doing it should work ok, although using jquery to populate a div via the $("#targetDiv").load("contentUrl"); function may be a cleaner way to do it. Anyway, in order to get your current implementation working, there could be a few things you want to look at:
I assume EnablePartialRendering is true on your ScriptManager (always worth checking!).
Make sure the eventTarget for the __dopostback call is set up as an async trigger for your update panels or that it is inside the UpdatePanel if you are only using one UpdatePanel. (See here for details)
Try returning false from the javascript code that executes in the onclick event handler if you have attached this to a button, to make sure the form is not being submitted normally by your browser when you click the button.
If I understand the question properly, you want the data to load after the page is in the browser. If this is the case, then you can fire an event with JavaScript when the page loads on the client.
One method I've used is to put a hidden (with CSS, not any property) button on the page and 'clicking' it with javascript. The event of the button click event will need to be wired in the page's code. Also the button would have to be in an update panel that either contains the grids you want to be bound or has the appropriate triggers to cause them to reload.
You might look at JQuery to get manage when this code gets fired. The $(document).ready(function(){ /* Your code here... */ }); method will fire after the entire DOM is available, which is faster than waiting on the entire page to load (images and so forth).