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.
Related
Currently I have a site that loads everything on initial load (when it's not a postback). Then it proceeds to load more data that should be fine to load regardless if it's postback or not. I thought everytime the page is refreshed or the button is pressed there is a postback. What I thought that if the user doesn't go to another page, any action he takes will be a postback.
However I'm getting very inconsistent errors when the site is actually on a server and was curious if perhaps, when clicking a button after a bit of inactivity, will the server possibly forget about the previous activity and treat the action as the person hitting the site for the first time again?
Below is how the button is defined....
<asp:Button CssClass="btn btn-default controls" ID="btnAddAdditionalCom" runat="server" Text="Add Comment" OnClick="btnAddAdditionalCom_Click"/>
Any asp:button click will cause a postback to the server because asp is a server side language so it has to talk to the server to execute the button click. If you want to do button clicks without talking to the server use something like javascript
You cant modify it.
Because this is a essential concepts in asp.net.
Even you cant change the value of IsPostback Property (It has no setter).
If you want to treat Postback as page load then u forgot the need of IsPostback
I have a aspx page. By default, when the page loads the focus is on first textbox. I want to remove the focus to nothing. I am developing this website for a mobile device.
We have come to this nothing conclusion due to some cross browser restrictions we faced with IE.
Page.Focus(); in the init is not working and I don't want to set up the focus to anything.
This information is all I have. Hope it is sufficient for possible resolution.
I will appreciate your feedback and time spend on this query...
An alternative can be to create a hidden control and move the focus to that control
If you're able to use jQuery why don't you do
$('#idOfInputWhichKeepsOnGettingFocus').blur();
If not, create a new first field
<input id="youCannotSeeMe" style="position:absolute; left:9001px;" />
This works:
Page.SetFocus(this);
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.
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.
in my application i have the playvideo page where video will play, below that i have the option for sharing the video like adding to favorite ,playlist and sending mail.
when i click on any of the link the page is postbacking and video will start from the first.
i place update panel for link button even though it is not working (video is playing from the first i.e., page is postbacking. can u help me. thank you
Actually, the part of page that is within the UpdatePanel does the postback. Make sure you have only those controls(for instance, your links) inside the UpdatePanel.
Alternatively, you can use multiple UpdatePanels; for instance one for your video and one for the links. In this case note that, when one UpdatePanel gets updated other UpdatePanels also gets updated, which you may not want; so all you have to do then is to mark the UpdateMode property to Conditional and call YourDesiredUpdatePanel.Update() method manually - whenever required.
Btw, updating selected portions of the page also reduces the load on the server
Or you may want to look into using client callbacks instead of a postback. But since client callback uses XMLHTTP, which means Microsoft implementation of AJAX, therefore callbacks are just awesome as long as your are working with IE.
You might want to try taking advantage of Page Methods to do the work you need done server side.
http://encosia.com/2008/05/29/using-jquery-to-directly-call-aspnet-ajax-page-methods/
Also, if you want to prevent a control from posting back, you can add return false to the end of your javascript onclick event on the control.
For example, if you had an asp button you were using you could do this:
<asp:Button ID="myButton" runat="server" OnClientClick="DoThingsInJavascript(); return false;" />
Or if you were just using a standard button you could say:
<input type="button" onclick="DoThingsInJavascript(); return false;" />
I've never really liked the update panel and I have sometimes found it's behaviour awful. Have you thought of trying something like a proper ajax call from Javascript