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.
Related
I have a page some 2 ASP Tabs and with an UpdatePanel on the first tab. Inside the update panel (on page_load), I dynamically create a table that contains rows with cells for an image, some text, and an ASP:Button. I'd like the button, when clicked to switch tabs from the first to the second. Instead, all it does is refresh the updatepanel it resides in. How can I stop it from behaving that way? How do I get it to perform a function of my own design, instead of posting?
Thank you,
You can add javascript click event and stop it to do post back by returning false;
In Code behind, where you add button dynamically.
btnChangeTab.Attributes.Add("onclick", "return YourJavascriptFunction();");
In Client side.
<script type="text/javascript">
function YourJavascriptFunction()
{
//Your javascript code here
return false; //the will stop from postback
}
</script>
I have a complex page. Basically, it is a ListView with images displayed through handlers. Paging is done through a datapager. This is all wrapped in an Ajax UpdatePanel so it pages seamlessly.
When the user sees a image they like and click on it, it should display in an image above the ListView. This work when I DON'T use the updatePanel, but of course, then I get flicker. Wrapping it in an update panel results in the paging working. When the user clicks an image it goes to the db as expected, but it simply never updates the image being displayed.
Here is how the image that is clicked on is defined.
<asp:ImageButton ID="imgbtnImage" runat="server" ImageUrl='<%#"~\Handlers\ThumbnailDBHandler.ashx?id=" & Eval("ID")%>' CommandArgument='<%#Eval("ID")%>'/>
does yout asp:ImageButton stays "in" update panel? 1 more thing, set update panel to use child as trigger. Because the event that postback in binable control is sometime not the control itself. It use the bindable control to postback.
eg. i have button in each grid view rows. when the button clicked, the update panel doesn't read the click event. it read the event as GridViewRowCommand. Not button click.
so set update panel to use child as trigger ans set to always update should solve the problem
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.
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.
On details view, I would like to hide the new button.
On page load I have successfully done so by the following code:
dtvwMyProfile.Rows[5].Cells[0].Controls[2].Visible = false;
But how do I hide the New button when I hit cancel or update button after I am done editing.
The New button keeps showing up. How do I hide it completely from the screen.
In some event, the visible property keeps changing to true and how do i find out that event?
I want to be able to do it at run time instead of design time.
Dynamically changing the properties of child controls created by the DetailsView is not recommended.
If the button is being created by the DetailsView itself then all you need to do is set AutoGenerateInsertButton to false and you can do that in Page_Load.
I do not recommend randomly selecting a page event and handling it. If you do that then chances are it will just break again when you change something else.
Maybe try to do that in the ModeChanged event handler, which fires after the mode changes... But can you ensure new is always at position 2? You may want to verify the button by its text or command name.