Using OnClientClick to open a chart window fails after the first use - c#

I am using VS2015 with Windows10 and C#. My app has 4 options, all of which execute serially in the same window, displaying output in a gridview; some options also display a button that charts a selected row in a separate window.
Switching between options works fine, and the first time that I chart works fine. My problem is that when I close the chart window, run other options, then come back to one that charts, the button click fails. A window is displayed with the chart icon so OnClientClick appears to have run, but OnClick never executes and the chart is not filled.
I know no Java so do not know how to debug it. Can someone please suggest a fix or an alternative that does not use Java!
Here is the critical code in the button click.
<asp:Button
ID="GoChart"
CssClass="button"
runat="server"
Text="Select, then Chart"
Visible="false"
Style="border-radius: 0.4em; width: 9em; float: left; margin-left: 1px; color: white;"
ToolTip="Select a row in the grid, then click here to chart the row. "
OnClick="GoChart_Click1"
OnClientClick="window.open('NewChart.aspx','_blank');return false"/>
On the second use of the chart button, GoChart_Click1 is never reached.
Thanks for your help.

The function GoChart_Click1 should actually never be executed because in the OnClientClick you return false signaling the browser to not execute the default behaviour of the button which would be to call GoChart_Click1.
Remove the return false; so that GoChart_Click1 is executed.
However, I don't think this will solve your problem since I don't see how you could do something with the newly opened window from within GoChart_Click1.
I suppose you need to share the source of GoChart_Click1 and the source of NewChart.aspx to get a more detailed answer.
I suppose that whatever code you have in GoChart_Click1 that fills the chart would be better placed in the load event in NewChart.aspx.cs directly.

This
OnClientClick="window.open('NewChart.aspx','_blank');return false"
To
OnClientClick="window.open('NewChart.aspx','_blank');"
Return false will stop the service side Click of the button. If you want service side action to be executed after Client Click remove the return false part.

Related

Show Popup Message based on Event in C# SharePoint WebPart

There is a Visual WebPart being developed in SharePoint 2010. On load, a set of methods that get and fill information in the WebPart run in the Page_Load method. Somewhere in this process, there needs to be a popup message box or alert box notifying the user that this particular bit of information is not available.
The problem is doing the popup message. A MessageBox.Show will not work in this particular situation as it is a SharePoint Visual WebPart, which is an extenstion of ASP.NET. Adding System.Windows.Form is possible and it would make MessageBox.Show work, but only on the development machine. It will not work for any of the clients on their browsers. Adding the following to the ASP code is possible, but one of the objectives is to minimize user interaction.
<asp:Button ID="btnCheckInfo" runat="server" Style="z-index: 101; left: 216px; position: absolute;
top: 160px" Text="Check Information" OnClientClick="return confirm('change a record, would you like to continue ?');" />
Having this happen automatically instead of having the user click a button would be ideal.
Is this at all possible? Is it possible to add a popup message box of some kind to a SharePoint Visual WebPart that can be called/triggered within a method instead of as a click event?
Hopefully the question is clear enough. I'm not an experienced C#, .NET or SharePoint programmer.
Thank you in advance for you help and advice!
You can use the RegisterStartupScript to add some javascript to your page from anywhere you want (ie in the page_load method)
if(something)
{
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "confirm", "change a record, would you like to continue ?');", true);
}
You would need to handle what happens when the user clicks OK

Asp.net c# Button click call a procedure and Also opens in a target_blank

I am trying to make a button that when clicked call a procedure but also opens in a pop-up. I can't find how to do it because all the search i did only tells me to put it on te clientclick :
<asp:Button ID="cmbGen" runat="server" Width="240px" Text="Générer le rapport" OnClick="cmbGen_Click"></asp:Button>
the onclick opens up a pdf, and its not working well on Ie, so, to solve this i would like the pdf to opens in a pop up
not sure what i could do.. anyone got an idea ?
EDIT
The code is pretty big, but basicaly, depending on what checkboxed were checked, it will create a pdf file and show it. this works pretty well, but it opens up in the current page, i would like to make it in a pop-up
A Button always submits a postback to the server on the current window, so you can't directly tie a new window to it. You'll need to write some javascript to do that, and open a popup window.
You can do this lots of ways - you can hook up an event handler to the button so when it's clicked, it immediately opens a new window, and that window is pointed to your server code which returns the PDF. Or you can do a regular postback, and return some javascript that pops up a new window. But either way, javascript is the only way to get a popup from a form button.
Liam's suggestion of making a link instead of a button is probably the simplest method - you can throw an image on that link to make it look like a button if you want.
EDIT
Based on your comment on the other answer, your simplest bet would be to return some javascript on the button click method, using ClientScript.RegisterStartupScript or whatever Microsoft is recommending these days. You can do whatever logic you need to first, then get that into a new handler either through session or querystring parameters, and have the client pop up a new window pointing to that handler.
Can't see you c# so it's not 100% sure what you want but why use a asp:Button at all:
Générer le rapport

Validation prevent check box to auto postback

I have following checkboxes on my page:
<asp:CheckBox ID="rbBuilding" runat="server" AutoPostBack="True" OnCheckedChanged="HandlerPackageOnCheckedChanged" Checked="True" CausesValidation="False" />
<asp:CheckBox ID="rbContent" runat="server" AutoPostBack="True" OnCheckedChanged="HandlerPackageOnCheckedChanged" CausesValidation="False" />
There is an logic on postback based on combination of checkboxes clicked. Everything is working fine except one case:
I'm opening additional telerik radwindow which has some validation within its own validation group. If I close the window with any validation error, then the first click on any of that checkboxes
does not do postpack.
Only FIRST click is not working. next time I click everything is working fine. I've tried to add check boxes to theirs own validation group and change casing validation to true. But behaviour is exactly the same. When I add test javascript method to onclick for that checkboxes then this method is fired without issue. There is just no postback.
I also tried to reset all validators for window validation group on window close, they are reset, but behaviour is not checking, and first click is not working.
UPDATE:
I've made one more check and realized it only happens if I do in javascript:
window.Page_ClientValidate("MyGroup")
Which I have to do before do some calculations on popup window.
During dynamic validators, when updating validatable controls eveything is working properly, even if validation fails. So the problem is *Page_ClientValidate*
I know this is an old question but I ran into almost the exact issue and thanks to the following link I was able to resolve the issue:
Issue with postbacks and clicking on controls twice
I ended up adding this code to my code behind to add a javascript event handler for the checkbox's click event:
Checkbox1.Attributes.Add("onclick", "checkboxChanged();");
I then added the following javascript:
function checkboxChanged(arg1) {
Page_BlockSubmit = false;
}
The checkbox in my situation was also set to have CausesValidation set to false but I don't think that's required for this fix. Hopefully this helps someone.

Checkbox problems inside jQuery dialog and Repeater

So I've been basically beating my head against the wall on this for a while now. Excuse me if I throw up too much code here, don't know a better way to explain it. I've got a Repeater with an ItemTemplate of:
<ItemTemplate>
<div id='FileFrame<%#Eval("Id")%>' class="view">
<userControl:ConfigFiles ID=<%#Eval("Id")%> runat="server" />
</div>
</ItemTemplate>
Some jQuery that sets up the dialog box for the div.
$(document).ready(function() {
$(".view").dialog({
autoOpen: false,
title: "Configuration Files",
buttons: {},
height: 600,
width: 800,
open: function (type, data) { $(this).parent().appendTo("form"); }
});
});
and some more jQuery that opens the dialog.
$("#FileFrame"+ConfigId).dialog('open');
Now the User Control has a bunch of checkboxes inside of it inside other repeaters along with a "Download Checked Boxes" button. The problem is that when I go through debugging and click the button, none of the checkboxes are ever read as checked unless I initially set the Checked="true" on the aspx page.
Here's the a snippet from the code behind where it's failing to do what I thought it should do.
foreach (RepeaterItem item in FilesRepeater.Items)
{
CheckBox box = item.FindControl("DownloadFileCheckBox") as CheckBox;
if (box.Checked) //<-- always false unless I set it to true in aspx,
// then it's always true
{/*do work here*/}
}
Any suggestions?
I had similar problem ( postback doesn't populate control values) sometime back. The problem was generated dialog was outside the form tag.
Use
$("#FileFrame"+ConfigId).parent().appendTo($("form:first"));
or similar code to move the dialog code inside of form
Hope this will help.
Ok, I'm not 100% sure what exactly happened (which is scary) but the code now works. My intuition says that something, somewhere, was wrong with a piece of JavaScript and causing the browser to just abandon the following JS. Bottom-line is that the solution that I posted in the question does work.
I think the main problem was that there was a JS function that I was calling that wasn't being loaded or wasn't within the scope of where the call was being made. If I find out more I'll be sure to post it here.

Disable an asp.net dynamic button click event during postback and enable it afterwards

I am creating a button dynamically in my code and attaching a click event to it. However I have to prevent people to click it while there is a process going on. So when it is clicked once, it should be disabled and when the process ends it should be enabled. How can I do that?
Thanks.
onclick="this.enabled=false" add this from your code behind to your control
btnAdd.Attributes.Add("onclick", "this.enabled=false;");
This link explains in detail http://encosia.com/2007/04/17/disable-a-button-control-during-postback/
If you are processing via ajax when the button is clicked-
1. Disable the button when processing starts
2. Enable the button after processing completes
If the button postbacks, the best way is to disable the button when it is clicked via javascript [I won't suggest jquery just for this particular task]. Since after postback the button will be enabled as it was earlier, you don't need to worry about enabling.
<asp:Button ID="btn" runat="server" OnClientClick="disable(this)"
Text="Click me!" OnClick="btn_Click" />
<script type="text/javascript">
function disable(control)
{
control.disabled="disabled";
//added alert to give the snapshot of what happens
//when the button is clicked
alert(100);
}
</script>
Hope this helps.
I would use an UpdatePanel arround the button. On click you can serverside disable the button. Use a trigger on the updatepanel that looks every x seconds if your extern process has returned a result. And I would advise you to source out long running processes into a windows service.

Categories