Right now I have a radgrid that is filled with checkboxes. If I click on a check box it calls my code behind checkchanged. In check changed it checks and see if that item is active if its not it throws an alert. I want to change that alert to a confirm but the radajaxpanel doesn't appear to have a method for confirm so I figure I need to create one in javascript and call it in the code behind.
What I have now
else
{
RadAjaxPanel1.Alert("The event you selected is currently In-Active");
}
So I assume I would need to change that to a call of the javascript or something similar to call for a confirm and then return the response in the codebehind to either continue or stop.
EDIT: If this helps maybe what I am trying to explain is. On codebehind trigger a javascript method to run and return a value for my codebehind to evaluate and continue or stop running.
EDIT 2:Or what I want to change is on clientclick it calls the javascript and if the javascript return Yes then it calls the codebehind. Maybe that is more likely and possible.
Related
I have an ASP.NET C# web form that uses jquery to validate user input before that input is handled by the server. When I say "validate", I mean that I check to ensure my user has given input in certain required fields before anything else happens. This check is wired to the "OnClientClick" event of an ASP.NET button control. If the client script finds missing input, it returns false. Otherwise, the button's OnClick event fires.
<asp:Button ID="submitBtn"
OnClientClick="if (!addBtnClick(event)) { return false; }"
UseSubmitBehavior="false"
runat="server" Text="Submit" OnClick="submitBtn_Click" />
The inputs to be checked consist of textboxes and drop down lists, both of which are coded in the page as server controls, and marked as required by a class value. I check the value of these inputs one at a time using the "each" function, and get the value of the input being checked with "$(this).val()".
$(cls).each(function () {
var val = $(this).val();
// do other stuff
});
My problem is that this is somehow causing an "Invalid postback or callback argument" error, and I know it's "$(this).val()" that's the culprit because if I comment out only that, passing in some generic value to my variable for example, my application runs fine.
I've tried registering my jquery code with RegisterClientScript, but that doesn't change anything. Has anyone seen this before?
EDIT: "$(this).val()" continues to throw this error even if the server-side isn't involved. I'm using this code to reset my form as well, clearing all input fields. After posting this it occurred to me that some of my textboxes have event listeners attached, so maybe this is where the error is coming from?
Turns out, no. Even with my event listeners commented out, I still get the error on the client side. I can use "$('input').val('')" with no problem, but this clears all the input fields and I need to be able to ignore certain ones.
I have a web forms application that uses signalR. I want to execute a method on the click of a button but when I click the button nothing happens. My hub class is defined as follows:
I also use the method "generateStatistics" in the hub class:
Now my client code is supposed to run the generateStatistics method on the click of a button. Here is the button code:
And finally this is what my client code looks like:
So, when I click the button nothing happens or at least the method isn't running because my breakpoint is never hit in the generateStatistics method. I did a bit of client javascript debugging in IE and it seems as though the connection is being made properly but the button click handler just doesn't seem to do anything. I guessed that it might be because the button is an asp server control with the runat specified but I turned it to an input html control and it still didn't seem to work or run the method. If you are wondering what the purpose of me using signalr here is that in the generateStatistics method I update the client with progress messages which you can infer from the javascript created method addProgress.
When you use ASP.NET, the HTML element ID will be different than what you specify on the control.
Try to use this instead:
$('#<%= btnStart.ClientID %>').click(function () { ... });
I have code that when a user wants to page through a GridView, it asks them (using a JavaScript confirm) if they want to save the data from the grid.
So, I'm able to get the confirm to work (with the code-behind saving function), but I'm noticing that it's not firing the OnPageIndexChanging method - which basically defeats the purpose here.
So, to summarize, can JavaScript access the OnPageIndexChanging method?
Thanks a lot
The OnPageIndexChanging event is a server-side event, so it's not surprising that your Javascript handler isn't getting triggered.
I'm not sure if ASP.Net has a "built in" way to do this; but you can do it by attaching your own Javascript listeners. Here is the general approach (I'm using JQuery to make it easier):
Write a JQuery selector that gets all the paging links that you want to confirm.
Add a click listener for each of those links
Make the confirm function the handler for those listeners
So, the code would look something like this:
$("#grid a").each(function () {
$(this).click(function () {
return confirm("really?");
});
});
Notes
Here grid is the ID of the GridView control, so #grid a selects every a tag within my grid.
Using return confirm() returns false if the user does not confirm, which effectively cancels the click event.
I'm creating this form (.net) where i have a select with a postback, that will trigger a action depending on which option i select. I'm trying to use the jQuery Validate Plugin (plugin website) to validate my form.
My problem is, when i validate the form, and my select is marked as invalid, the validation plugin overwrite it's onChange method to make it unmark when i change the value, the thing is that it's deleting my __dopostback from the onchange, making the form 'useless'.
Is there a way to the plugin validate my selects without deleting my postback action from the onchange?
I know this is an old post, but I had a similar situation and was able to resolve it like this. Just thought I'd post it just in case someone else found there way here. I'm using jQuery Validation Plugin 1.9.0:
$('#aspnetForm').validate({
errorLabelContainer: "#messageBox",
wrapper: "li"
});
$("input[id$='myButton']").click(function () {
SetRules();
if ($('#aspnetForm').valid()) {
// form passed validation
} else {
$('#aspnetForm').resetForm();
return false;
}
});
function SetRules(){
$("select[id$='myDropDown']").rules("remove");
$("select[id$='myDropDown']").rules("add", {required:true});
}
My validator is set up so errors display together in one designated div. When I click the button, the validation fires and displays all the elements in that div and marks the fields that are invalid, including the select (all choices are red), and when I change the selection my autopostback fires and the colors of the select change back to their old value (assuming the choice passed the validation).
I am pretty new at this plugin, so I can't explain it too well but my thought process was to try and get the form to validate and show the errors, and then reset the controls back to their original state while still keeping the error messages visible. I was expecting to lose the red error highlighting, but somehow that retained while also bringing back the select's postback.
Also, I do not know if setting the rules in this manner contributed to this working or not; I had to set them like this for various reasons, the biggest one due to needing the selector for .NET's automatically generated IDs.
Ok, I've got a lightbox with a small form (2 fields) in it, inside an UpdatePanel, and I want to close this lightbox (must be done via javascript) when the 'Save' button is pressed.
However, there is a need to have a server-side CustomValidator on the page, and I only want to close the lightbox if this returns as valid.
Does anyone know a way to trigger javascript (or jQuery) code from a server-side validator?
You can add a little snippet of code using the ScriptManager to execute after the response comes back to the UpdatePanel.
if (Page.IsValid){
ScriptManager.RegisterStartupScript(
customValidator1,
typeof(MyPageClass),
"closeBox",
"myLightBoxVariableOnThePage.close()",
true);
}
When that server side validator runs, it will send a whole new page to the browser. Anything that was shown in the browser before was destroyed, including any state kept in your javascript. If new page bears a strong resemblance to the old page, you should consider this a happy coincidence.
Therefore, the thing to do here is rather than executing a javascript function, have your CustomValidator make the correct changes to the page on success so that it's rendered to the browser correctly in the first place.