Avoid postback on gridview event - asp.net

1
I've got popup (using javascript) working in a kind of gridview. When you click a button on one grid, it displays a popup window containing another grid of information, based on the row clicked in the first grid.
This works well... I've enabled editing in the grid that is popped up. When you click edit though, the popup window disappears. If I click the display button in the first grid though to bring the popup window visible again it displays, and is now in edit mode.
Is there a way to make postbacks in the popup not close the popup?

Hidden variable is way to go.
<input id="popupState" type="hidden" value="1" runat="server"/>
Set it from javascript and make the popup visible or invisible based on hidden variable's value in
jQuery(document).ready(function($) {
// your code goes here.
});
if you are using jQuery or if you are using Microsoft Ajax controls i.e script manager etc.
function pageLoad(sender, e)
{
//your code goes here
}
both of the javascript methods fires once the page is loaded on client. Better if you use jQuery one.

Related

Need an asp.net control to click the button in another asp.net control

First time I have used the site. I appreciate the help I have gotten from the users before and hope to contribute as well as ask. Now, for the question.
I am developing a static toolbar that rests on the bottom on the webpage. The purpose is to display a couple of values to a user purchasing something and for the toolbar to update the information to reflect the choices. There is currently a box on the page that does this, but it rests at the top and the user would have to continuously scroll to see options appear, price changes, etc.
The values update just fine with the price in that box when certain check box buttons are clicked that auto-refresh the page (due to these check boxes changing pieces of the code). However, some things that can effect the price require a button on the page that 'recalculates' to be clicked. The information on this page is put on the page with a controller. The toolbar I am creating is a separate control.
What I am trying to do is have a button within the toolbar that will mimic the actions of the purchase button that recalculates. I tried doing this:
Code on control page for toolbar:
<input type="button" id="buttonID" class="buttonClass" runat="server" onclick="__doPostBack('<%= btnIDOtherControl.ClientID %>','OnClick');" value="Recalculate" />
Code on control with the purchase info:
<asp:ImageButton ID="btnIdOtherControl" runat="server" ImageUrl="~/image.jpg"
AlternateText="Recalculate" OnClick="recalcFunction_Click" />
That is just the current iteration. Before I did not have the 'OnClick' piece of the __doPostBack, I had ''. I also tried using a bit of jQuery. There are quite a few questions about firing an ASP.net button from javascript, but none seemed to work.
What happens is I have gotten it to a point where clicking the recalculate button in the toolbar actually DOES refresh the page, but none of the values change. If I click the recalculate button from the purchase page (where it exists normally), the value in the toolbar does not change even though the values on the page do. If I hit the recalculate button from the toolbar AFTER recalculating from the main page, the toolbar values reflect the regular values. Any other normal use of the page (such as the checkbox that auto-refreshes) will change the values correctly in both places.
If more info is needed just let me know.
Appreciate the help ahead of time!
This has to be done by using javascript or jQuery.
Use the code below:
$("#buttonID").click(function(){
$("#btnIdOtherControl").click();
});
This will trigger the button on other control to be triggered.
PS: Make sure that the ids are correct once the page is rendered in html as visual studio will append the ids of the button in the control to be (id of the control)_(actual id of the button) i.e. If on your page you have referenced control as
<user:control id="control" runat="server">
The id of your button (buttonID) on html will be control_buttonID, so you will need to use that (control_buttonID) in jQuery.
So your code will be
$("#control_buttonID").click(function(){
$("#control1_btnIdOtherControl").click();
});
On you other control make a public property with set only and call your button's click event in it, Then on your working control you have to call only that public property of other control. it should be like this :
public void PublicPropertyCallingEvent
{
set
{
Button1_ClickEvent(null,null);
}
}
You have to access this property only wherever you need.

Problem with Ajax control toolikt Modal Pop control

I have an ajax control toolkit modal popup on my page and in that modal popup i have a gridview on which user select some item through checkbox on each row of gridview. Whenever user check or uncheck on checkbox my modal popup automatically hide. I have set autopost property of checkbox set to true becuase im perporfing some calculation on each checkchanged event. what may be the problem
Your page is posting back because of the autopostback="true" on the checkbox, thus hiding the modal popup.
Look up 'ASP.Net Page Lifecycle' for further understandinf. It is important to know how this works.
I'm sure you'd also like to know how to solve this.
You could:
Set AutoWireUp=false on the page, but then you'd have to wire all events on the page manually. Since you aren't familiar with the Page Lifecycle, I'm not sure how successful you'd be.
Use a javascript-only modal popup.
Perhaps an UpdatePanel can be used.

Page_Load after Modal Popup

I have a page with a user control which gets some data updated via a modal popup. Upon clicking "ok" on the modal popup - the new data is being written to the database - but the base page doesnt "reload" to show the updated data. How do I get that to happen?
1) Don't set the OKControlID property on the ModalPopupExtender.
2) In your Page_Load, set OkButton.OnClientClick = string.Format("$find('{0}').hide();", modalPopupExtender1.ClientID);
Explanation:
Setting the OkControlID stops the button from posting back. Instead, manually use javascript to hide the extender, which will allow the button to post the form.
You'll either have to update that control using ajax, or you could just do a Response.Redirect(assuming your modal is .net, or document.location if js) back to your page after your data has been updated.
Make sure the "Ok" button in your modal popup is causing a postback. If you want it to be ajax-enabled, make sure to put it inside of an update panel.

How to disable autopostback on button

I've got some dynamic created buttons in my GridView (adding them OnDataBound), but when I click some button in makes a strange PostBack and all my added button desappears... Also Click event doesn't happens.
How to :
1) Make my dynamic Button inside GridView do not disappear after clicking one of them.
2) Make this click methode works somehow ...
Im making it this way :
B.Click+=EventHandler(fun(_,_) : void { this.LabelCurrentCategory.Text="AAAA"; });
But It makes no sense... Only hides dynamic elements :(
On a postback any dynamic page elements will be lost. *
Can you not stick to client-side code, and use jquery ajax to call a pagemethod on your code-behind page?
EDIT: *Unless you recreate them on the page-load.

Can you perform an action based on a seperate window in asp.net?

I have a page of search results, and clicking one opens a new window where they edit the information about it. Once they finish, they currently have to hit "search" again to refresh the results to ensure it saved correctly (it refreshes the search results and reflects the new status).
Is there any way to trigger the page to automatically refresh (ie. automatically click the search button) based on the popup window closing or through some other means?
I echo the sentiments to do this without popup windows, but if you really need to...
I would do this with an update panel wrapped around the results and some javascript added to your save button on the popup page.
On your popup page, I guess you have a button to save your work, something like:
<asp:button id="btn_save" runat="server" OnClick="Save" Text="save" />
on the codebehind:
protected void Save(object sender, EventArgs e)
{
// save code ...
// bla bla
// Add this
ClientScript.RegisterStartupScript(this.GetType(), "save", "<script language='javascript'>updateResults();</script>
}
On the results page add this
<script language="javascript">
function updateResults()
{
__doPostBack('updatePanel_results','');
}
</script>
and wrap your results control in an update panel (in this example called updatePanel_results). In your page_load, you'll probably need to code to call your refresh resutls method.
I'd really avoid having the application flow spanning two windows if possible. Why not impliment some kind of modal dialogue when the user clicks an edit link?
Check out jQuery's modal form implimentation to see what I mean:
http://jqueryui.com/demos/dialog/#modal-form
Opening window does not look like the ideal solution here.
In the new window you have access to parent window in javascript. You can use it to fire refresh/or some other function in mail window.
Is there any way to trigger the page
to automatically refresh (ie.
automatically click the search button)
based on the popup window closing or
through some other means?
You can register a JavaScript event handler for the OnUnload event. However, in my experience it's not reliable (browser-to-browser inconsistencies, etc).
Have you considered using Ajax to keep the search results on the same page as the original window? Or maybe a small Silverlight control?

Resources