Does the <asp:Textbox> have a onFocusLost event? [duplicate] - c#

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Lost Focus method for asp.net textbox?
i want to check the data entered by user on the client side.
it is necessary for me to use control.
is there any way so that i can check after client move on to the next input and i can check the data by javascript ?
<asp:TextBox ClientIDMode="Static" onblur="return userCheck(this.id)" onkeyup="return userCheck(this.id)"
ID="txtUserName" runat="server" Width="180"></asp:TextBox>
here i have used two events but i want to use only one.

You can do that with onblur event using javascript.
f.e something like that:
<asp:TextBox runat="server" onblur="Javascript:alert('1234');" />

For what you want to do, you can set the textbox to have AutoPostBack=True; any time the text in the box is changed and the box loses focus, it will post back to the page; you can use the TextChanged property, as well, if you don't want to post back, which will check to see if the text of the TextBox has been changed between posts.
Finally, you can bind the JavaScript onFocus and onBlur events to the textbox, and handle changes to its contents via JavaScript:
http://support.microsoft.com/default.asp…
Source: http://answers.yahoo.com/question/index?qid=1006040618831

Related

How can I make a RequiredFieldValidator trigger a message elsewhere on the page?

I have a page with a repeater containing RadioButtonLists which have requiredFieldValidators attached to them. I need to keep the RFV next to the control (it's the only way I can get it to work to be honest!)
However, the form is made up of a few sections contained in an accordion. This means that when the form is submitted, the item that has failed validation may not be visible, so the user won't know where the error is.
Is there a way I can also have a message by the submit button which is triggered by an RFV changing saying "please go back and check your answers" or something? I guess I'd need to use JQuery / JavaScript as it would be clientside.
There is a special ValidationSummary control for that:
<asp:ValidationSummary ID="Summary" runat="server"
DisplayMode="SingleParagraph"
HeaderText="Please go back and check your answers" />
This control is used to summarize all validation errors on the page.
Try "ValidationSummary". look for example from here.
http://www.w3schools.com/aspnet/control_validationsummary.asp

required fields and asp.net

im working on an .aspx page in Visual Studio.
I want to have a text box that is followed by a drop down menu.
if the user enters any input in the text box id like for it and the drop down menu to both be required before the corresponding button can be clicked.
is the best way to do this to use a RequiredFieldValidator ?
I think what you attempt to do is Conditional Validation
This question is similar to your question for Conditional Validation ASP.NET
Yes, RequiredFieldValidator would work well for your scenario. Just be sure to enable it or disable based on 'if the user enters any input in the text box'
You can create validators for both fields and onblur of the textbox enable/disable the validators using javascript.
HTML:
<asp:TextBox runat="server" ID="txt" onblur="enableVaidators();" />
Javascript:
function enableValidators()
{
var val_Test = document.getElementById('<%=val_Test.ClientID%>');
var enableValidators = true;
// Perform check on whether to enable or disable based on your scenario
ValidatorEnable(val_Test, enableValidators);
}
how about using jquery?
everything is done on the client-side:
http://docs.jquery.com/Plugins/Validation/
I would use a CustomValidator which implemented logic based on the state of the TextBox.
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.customvalidator.aspx

JavaScript Yes/No Preceding ASP.NET Button Event

Hi I'm trying to learn more JavaScript AJAX. Basically I would like to have a popup Yes No on a delete button that would precede the actual C# event being fired. I could do this all in C# but I know doing it client side would be beneficial as it would reduce server load.
I'm not sure exactly how to go about this. Any ideas?
You can use the javascript function called confirm
onclick="return confirm ('Are you sure you want to delete this _____?');"
This text parameter is the text that will be shown in the modal with the yes and no.
The Yes returns true which allows the postback to continue, but the No returns false and will stop the postback.
EDIT:
As mentioned by XaiSoft and Cybernate, if you are using an ASP.NET button you can also use the OnClientClick property which will be translated to onclick by the server.
You can use OnClientClick property of the asp:Button.. along with the JS confirm..
Try something like the code below in your aspx/ascx/master:
<asp:Button id="cmdSubmit" OnClientClick="return confirm('Are you sure?')" runat="server" .../>
You can also use jQuery instead of the ugly default confirm. Here is a question addressing that.

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 url in text box

I have a textbox as follows:
<asp:TextBox runat="server" ID="txtOtherApps" Height="400" Width="400"
TextMode="MultiLine" ontextchanged="txtOtherApps_TextChanged" ></asp:TextBox>
How to display link in this textbox?
The TextBox allows you to display text which the user can edit. It does not allow you to display anything but plain text. To display a URL in the TextBox, simply set its Text property:
txtOtherApps.Text = "http://www.example.com/";
It wont, however, be a "link". Clicking the URL will cause a text cursor to be placed, allowing for the user to edit the URL.
It is possible if you use JavaScript
Use JavaScript on your text element - such that:
<input type="text" name="t1" id="t1" value="http://www.google.com" onmouseover="this.style.cursor='pointer' ;" onClick="window.open(this.value);"/>
Only Java script can do what you are asking for.
You won't be able to click on the link, but you can just set the Text property of the TextBox to the URL.
ASP.NET will render TextBoxes as textareas (in your case, because it's multiline) or inputs. These are standard HTML fragments which are just plain text containers. You can style them, but you can't really linkify the contents of them.
If you really just want to put the text of a link into a box, do this:
// either from the server:
txtOtherApps.Text = YourLinkString;
// or from the client:
<script>
document.getElementById('<%=txtOtherApps.ClientID%>').value = YourJsLinkValue;
</script>
If you want something to happen with the user clicks on the text area, you can add an onclick handler to it...but this would be weird.
You will need a RichTextBox. The .NET one is not available for web applications, but there are a few third party solutions available.
http://www.richtextbox.com/ is one of them, you will have to see for yourself if there is any available that suits your needs better.

Categories

Resources