How To Force The User To Have At Least One Selected Checkbox And Postback From Client-side JavaScript
Jul 8, 2010
I have two checkboxes: cb1 and cb2. They are both hooked up to an onClick event which checks if at least one checkbox is clicked. If this is not the case, it throws an alert and reverts the change. If a legal change was made (e.g. cb2 was checked, followed by cb1 being unchecked), the function calls the server function checkChange() which needs the object and eventargs.
I'm having trouble with the following:
Reverting the change: how can i find out which checkbox was clicked without adding an extra javascript function for the second checkbox? This has to be a scalable solution as more checkboxes may be added later.
How do I call the server function checkChange(). I am aware of "this.Page.GetPostbackEventReference" but I am confused as to the parameters it takes.
I have a user control which contains a CustomValidator which is used according to whether a RadioButton is checked or not (there are several RadioButtons, I'm only showing the relevant one)
There is some client + server side validation code (the server side code does exactly the same thing and is skipped for brevity)
<script type="text/javascript"> function ValidateDateFields_Client(source, args) [code]...
There are two instances of this control in the page. When running the client side version it hits the wrong one (the version of the control which is disabled). You can see from the generated HTML both are correctly specified. I'm not sure how .NET works out which clientside function to call given they both have the same name.
[code]... Do i need to add something in to scope it? What's the best way to achieve this? If I disable the loading of the second control everything works fine.
Basically I want to get some javascript to be sent back to the client and executed from a postback inside an UpdatePanel. Furthermore this is inside of a reusable WebControl. I've tried
this.Page.ClientScript.RegisterStartupScript and this.Page.ClientScript.RegisterClientScriptBlock but Firebug shows that those scripts aren't sent back in the postback's response.
I also tried straight up writing a <script> tag inside the control's main div in the Render method, which does get sent back but isn't executed. I got a hacky solution working, but ideally looking for a cleaner solution. The hack is to add a 1x1 pixel img with width/height set to 0 and use that for an onload event to execute the script and that works, but it seems like there has to be a cleaner way to do this.
Both of which give me runtime errors when the event is fired.Whats the correct way to access this text property client side?I tried this but it does not enable the checkbox...
Well, along with having to use == rather than .Equals, when you set a checkbox.enabled = false on the server side it raps the checkbox in tags and sets it to disabled=true; therefore you must set BOTH the checkbox.disabled = false and checkbox.parentElement.disabled = false; on the client side to enable the checkbox!The solution:
i'm facing an issue in asp.net application (c#). i want get the name of tabpanel.i searched in forum i found that with java scritp function i can resolve this issue but i couldn't.
I encouter some postback issue when using GetPostBackEventReference. Here is the Scenario:I have a javascript modal popup dialog and got a button in this modal dialog which used to select things (this is NOT an asp:button control)
When this javascript dialog HTML button is clicked, it will call the MS AJAX web service call by the javascript: eval() method. And this MS AJAX web service call is dynamically generated. So the code is like this:
var serviceCall = svcCall + "(" + parameters + ")"; //dynamically generate the MS AJAX web service call here eval(serviceCall);
//use eval to trigger the MS AJAX web service call
As you may all know, after complete the MS AJAX web service, you can define a callback function to handle the completion:
function OnComplete(result, userContext, methodName) {
//force to call postback manually eval($(userContext[0]).val()); [code]...
As you can see, this is how I bound the asp:button (i.e. btnSelectUser) 's Click Event to the asp:hiddenfield using the GetPostBackEventReference, and set the registerForEventValidation argument to false. I have also tried to use different ValidationGroup and set the CausesValidation to false.In summarize, I bound the asp:button's Click PostBackEventReference(i.e. __doPostback(....)) to the asp:hidden field's Value attribute, and using javascript eval() to eval this hidden field's value in order to manually trigger postback.
p.s. the btnSelectUser is an asp:button control and used to call out the javascript modal dialog.
Ok, here is the Problem:In the same page, there is some asp:validator, e.g. and , and of coz, when the page run into error, this validator and callout will display to the user. e.g. When the user didn't fill in anything and submit the form, the ValidatorCalloutExtender will display a ballon and tell the user. Imagine one of this ballon/validatorCalloutExtender come out and on top of your screen at the moment.
Then you click the btnSelectUser (asp:button) to show the javascript modal dialog, and in the dialog, you Add some users, and once you hit the SELECT button inside this modal dialog, a MS AJAX web service is trigger as mentioned above, and once this web service is complete, it eval() the asp:hidden field's value (i.e. __doPostback(...))......and do the postback manually.
However, because of the validatorCalloutExtender ballon has display, it somehow cannot trigger the postback in this way, but when I close the ballon/validatorCalloutExtender, the manual postback using eval() is just working fine. Even more strange is that, when the ballon is displayed, the first time I click the SELECT button inside this modal dialog it doesn't fire the postback, however, if I do the same thing again (i.e. open up the javascript dialog, and choose some users, then click the SELECT button again). It able to do the manual postback....and I don't understand why the first time doesn't work.
Maybe I've picked a totally inappropriate/bad example. What I have is a user control that contains a bunch of dynamically created Telerik RadGrids. My user control is added to a couple of Telerik RadPageViews that are part of a RadMultiPage that is used alongside a RadTabStrip. What I need to do is call a Javascript function in my usercontrol to update it's display whenever it's parent RadPageView is selected. So basically I have the following Javascript code:
function OnClientTabSelected(sender, args) { // Get the MyControl that is on this tab var myControl = $find("whatever"); // Call a method that updates the display myControl.doSomething(); }
n a form I have multiple group of controls which are grouped using validation group property. I want to assign validation group to asp.Button dynamically on client side using javascript on the base of item selected in drop down list.
Here is JavaScript which I am using, but it is not working. It shows validation group undefined but actually a default group is defined.
<script type="text/JavaScript"> function NextClicked() { var _ddlStatus = document.getElementById("<%=ddl.ClientID%>"); var _selectedIndex = _ddlStatus.selectedIndex; var _btn = document.getElementById("<%=btnNext.ClientID%>");
alert(_btn.ValidationGroup); // here in messge it shows undefiend, yet I have defiend a group in button as default.
if (_selectedIndex == 1) { _btn.ValidationGroup = "G1"; } if (_selectedIndex == 2) { _btn.ValidationGroup = "G2"; } }
- How can I uncheck a checkbox using client side code when the other checkbox is checked? - Is there a way to check server side on form submission that at least one check box is checked?
I have a requirement of adding server side variables in client side and other way round. Because I need to set a value from client side using javascript and access the same in code behind page.
I have a list of items on an ASP.net page. That list is selectable in that whenever the user clicks on one, the page does a postback and the server code stores the index or some unique identifier of the picture in a ViewState property indicating that it is currently selected.
I would like to minimize the load on the server and therefore I would like to store the index or unique identifier representing the image in some way on the client side. The best way I can think to do this is to store said information in a hidden field ), however I had two questions about this before I go crazy:
Is this a security risk in any way, shape or form (i.e., exposing implementation details of the page)? Is there a better/best way to do this that is more industry-standard? Does ASP.net provide a framework to do this that is cleaner than my idea? Seems like this would be a fairly common requirement to me...
Possible Duplicates: how to call server side function from client side - asp.net Calling ASP.NET Code Behind function from Javascript Calling ASP.NET server side method via JQuery While loading an aspx page, how is it possible to call a server side method with the client side code?Can u show one example?
I have two comboboxes and would like pass selected value and text to the server method (RadComboBoxItemsRequestedEventArgs) when the first combobox selected index changed.
Here is my code. But I am getting Javascript error message at this line. RadComboBox2.requestItems(item, false).
I'm working on developing a custom control to select items from a predefined list. This is accomplished via 2 ASP.NET ListBox controls, with a few buttons to trigger the movement of ListItems from one ListBox to the other (lets call these ListBoxes lstSelected and lstDeselected).
This is easy enough to do in ASP.NET or JavaScript independently: I have both working. However, if modifications are made via JavaScript, ASP.NET retains no knowledge of this. Is there any way to register the creation of of options in a select tag without AJAX?
I've got a function I wrote quite some time ago that works fine, but I'd like to speed up the process and lessen server load by doing the same job in Javascript.I seem to be able to GET textbox values ok, but I can't seem to SET textbox values (I'm'-a JS noob). Can anyone lend a hand in converting my VB.NET code to it's JS equivalent?
Protected Sub txtSellingPrice_TextChanged(ByVal sender As Object, ByVal e As EventArgs) _ Handles txtSellingPrice.TextChanged Dim SellingPrice As Double = Double.Parse(txtSellingPrice.Text.Replace("$", "")) [code]...
I have some validation JS code on client, that must be executed befor PostBack.If this validation code return 'false', postback is needless.How it can be disabled?
I want to enhance a composite control's client side, my approach is to recreate all method on JavaScript, so here I have some troubles:Can I call onclick event on client side otherwise on server side?the statement table.onclick=SelectRow(event) fires a bug!Code:
function Control_Init() { if( !(document.getElementById) ) { return; } for( var i = 0; i < Controls.length; i++ ) {
I am developing a web page where a user will submit some "Comments" on a form. When they click the submit button, I fire off some javascript that captures their current GPS location, which I store in a visible Text Box (for testing purposes). If the user is updating from a device that doesn't support gps, I add text to my textbox that says "Device does not support GPS".
When I get to the server, using a device that doesn't support GPS, that text comes through just fine. When I use my iPhone, I see the GPS Coords in my textbox, but that textbox value doesn't make it to the server.I'm thinking that there is a 2-3 second delay from the time that the button is clicked to the time that the java finishes retrieving the GPS. So the textbox text isn't set fast enough.I'm wanting to prevent a postback for 3 seconds (for example) to give the javascript time to update the textbox.