How do I trigger a jQuery function with a c# Calendar SelectedDateChange? - c#

I have a c# calendar control that triggers a form submission when the date changes. It is all set up and works fine (so I don't want to switch to the JQuery date-picker).
At the moment the form submits and redirects to a confirmation page. However, I want to change this so it pops up a Jquery UI dialog (or equivalent) with some Ts and Cs that the user has to agree to (with a checkbox) before they can submit the form.
I assume the simplest way to do this is to have a div with the Ts and Cs, checkbox and submit button in a hidden div that the thickbox shows. Question is, how do I trigger the dialog from the c# date change?
Been requested to add some code - trouble is, I don't know what to add!
If I was doing this with a button click, I'd put something like:
$("#btnSubmit").click(function (e) {
//...
}
But how do I do the equivalent to pick it up from a SelectedDateChange event?

You can use ScriptManager.RegisterStartupScript for registering a script at run-time.
What you need is something like below in SelectedDateChange event code in c#:
ScriptManager.RegisterStartupScript(this, this.GetType(), this.ClientID, "JavaScriptmethod()", true);
Replace JavaScriptmethod() with your javascript method or you can also write js in here too. This will execute the javascript method on SelectedDateChange event of C# calendar.

Related

how to prevent a save button from calling javascript validation when the same is used for update functionality

i am using a button which is used for both saving and updating data.I want to call the javascript validation function when it is used to save and not when it is used to update data.How can i do this?
a button that can perform save and update? in code behind? you may call your script when ur button perform save function
this is something like this
//save function - with javascript validation
Page.ClientScript.RegisterStartupScript(
GetType(),
"MyKey",
"Myfunction();",
true);
//update function
without javascript validation
You haven't really specified how your validation works; however, if you are using jQuery Validate, you can prevent validation on a "save for later" type button simply by adding class="cancel" to your input tag.

onUploadComplete event of asyncFileUpload

how to display a btn after onUploadComplete event is executed? It's not coming now even I say btn.visible=true inside that event..
I read in one of the thread that this event happens asynchronously so we have to write javascript for it and call onClientUploadCompete.
But do anyone know how to do it withoiut writing javascript? please its urgent thanx in advance!
You've got two options - to execute client-side using JavaScript and AsyncFileUpload's OnClientUploadError and OnClientUploadComplete, or to handle the server-side UploadedComplete or UploadedFileError events fired by your AsyncFileUpload object.
If you choose client side, you can still include your Button as normal and include CSS for it to be display: none, which can be then altered in the JavaScript with something like the following:
$get(<%= AsyncFileUploaderInstanceName.ClientId %>).style.display = "block"
If you choose server side, you'll be able to refer to the .Visible property of whatever controls you like, and can alter them then. However, you'll have to update whatever UpdatePanel the button would be sitting in for the button to be rendered on the page.

Get text box value on .cs page in asp.net

I want to develop an application in asp.net with C#.
In that application there are one text box and one label.
I want the following functionality:
When I press any key in textbox then I should get this value on .cs page i.e; code behind. And from .cs page I want to add this value to the label.
The problem is that there is no keypress event for an asp textbox and if I take a html text box then I don't get its value on .cs page
How can I come out with this problem?
Because a keypress on a textbox is a client side event but you want to perform server-side processing you will need to use AJAX requests.
You may find the following useful:
AJAX Toolit
Using Jquery to call asp.net page methods
In asp.net the TextBox will have TextChanged event but you will need to enable post back for the button and the event will fire when you tab out of the TextBox.
For the task you want either use javascript or add a button and when this button is do what you want.
I don't think this is a good aproach in web app., In this way you will end with a lot of post-backs.
However, if you still want this functionality. Texbox has TextChanges event, and if you also change the textboxs's AutoPostBack property to true you will get something close, but you will still have to move a currsor.
But it is still a terible solution. Why don't you simply use a button that fires click event instead?
Alternative solution is to use Ajax or javaScript,..
You can simply create a JavaScript-Method for this.
Your Textbox:
<asp:TextBox ID="textBox" runat="server" onkeydown="onFilterTextChanged()">
</asp:TextBox>
Your JavaScript, do a TimeOut to not do this every 0,0001 secs.
function onFilterTextChanged() {
if (timeoutID)
window.clearTimeout(timeoutID);
timeoutID = window.setTimeout(updateFilterText, 600);
}
Send the Values to the CodeBehind, textis your TextBox-Text.
function updateFilterText() {
var text = document.getElementById("<%=textBox.ClientID %>").value;
__doPostBack("<%=textBox.ClientID%>", "CommandArg" + text);
}
You won't need to do as many PostBacks as with the native TextChanged-Event and you can simply use this e.g. for Auto-Extender-Plugins. Pack the TextBox into an UpdatePanel and you're good to go!
Unless of course you do not NEED to go back to the server, in which case just set the labeltext in updateFilterText.

Display search results dynamically as typing

I am trying to build a SharePoint 2007 web part in Visual Studio.
This web part should search a sharepoint list and display the results.
What I want to accomplish is to display the results as soon as the user stops typing, so no clicking button involved.
Probably, a combination of text_changed event and onkeydown javascript?
Any thought would be great.
This sharepoint site is "Ajax-enabled", btw.
Thanks
I would suggest using jquery and keyup:
$("input#txtid").keyup(function () {
if (this.value.length < 8)
return false;
$.get("ServiceUrl", { arg: this.value }, function (result) { $("#output").html(result); });
});
The easiest way to take care of the UI part is to use the AjaxToolkit AutoCompleteExtender se MOSS, AJAX and the AutoCompleteExtender then all you have to do is decide how you want the searching inside the web service to work
I approached this by using an UpdatePanel in my webpart. Then I added a Button (more on this later) and a TextBox to the UpdatePanel.
I also have a JavaScript class which handles all of the logic for submitting a query after the user has paused while typing their query. It contains the event handler for the onkeyup event which is attached to the TextBox:
t.Attributes.Add("onkeyup", "javascript:oSearchClass.KeyUpEventHandler(event);");
I used setTimeout and clearTimeout to handle when the class should call a SubmitQuery function.
When SubmitQuery() is called, it makes the TextBox read only (so the user can't type anything while it is querying) and then "clicks" the button using click(). Since you're using a normal Button, you can handle the Button.click event like normal to re-query the list and display results.
If you don't want your user to see the button, you can simply put it inside a span WebControl that is hidden.
Have a look at this sample, it adds 'search as you type' to the standard SharePoint search box.
Automatically add ‘Search As You Type’ to every SharePoint page using Infuser.

How to Trigger a submit from keydown event in Windows Mobile in C#

I am working with C# and Windows Mobile.
I want to make a LeftSoftKey press trigger the "submit" action on a web page currently viewed in a WebBrowser window. In the HTML form being viewed there is a single form with an entry.
Currently I can capture the left soft key keydown event. What I can not find is how to either invoke, or trigger the WebBrowser to act as though either the submit button was pressed, or alternately the "enter" key was pressed causing the default submission. Either is an acceptable action.
You'll need to write some javascript for the webpage on that listens to the key-press and then submits the FORM programatically. The easiest way to do that would be to use an existing javascript framework like jquery.
The raw javascript code (without jquery) would be something like this:
<script type="text/javascript">
document.onkeyup = handleKeyPress;
function handleKeyPress() {
switch (event.keyCode) {
case 25: // some number corresponding to your desired key
// do something;
}
}
</script>

Categories

Resources