Leave event of the TextBox Validation - c#

So i have Two textboxes, both being used by Barcode scanner. Textbox1 is material and Textbox2 is progress. I would like to clear TB1 and TB2 when TB2 scans "F4" and focus Textbox1.
I couldn't figure it out so i came to you stack.
Thanks for any help.

So capturing bar code scans is tricky. The event model is the problem. To make matters worse, you're using ASP.NET so it's going to be even harder. But, it's possible with JavaScript. Consider the following jQuery:
$("#textBox2").on('keyup', function(event) {
o = $(this);
if (o.val() === 'F4') {
// post the values back to the server via AJAX
// clear the text boxes
$("#textBox1").val('');
o.val('');
// focus the first text box
$('#textBox1").focus();
}
});
where #textBox2 is the id attribute of the input element you want to interrogate and #textBox1 is the id attribute of the input element that houses material value.
This could technically be hacked with the ASP.NET post back model, but it wouldn't be pretty. You'd have to use the same JavaScript event to actually force a post back:
$("#textBox2").on('keyup', function(event) {
o = $(this);
if (o.val() === 'F4') {
$('#formName').submit();
}
});
where #formName is the id attribute of the form element you're inside of.
And then server-side you'd have to consume the TextChanged event of the second text box and check its value to know you ought to clear the values of both. It's just a little fickle.
Finally, using this post back model, you'd have to register some client startup script to set the focus to the first text box because you'll need some JavaScript to do that. As you can see, it just gets uglier.

Related

ASP.NET: After POST validation fails focus is on the first input. How to remove that?

After the validation fails ( if input is empty) for POST form, the cursor is set on the first input that has failed and the validation styling disappears:
I tried using jquery functions like .blur() or .focusout() after Login button is clicked, but it did not work.
Any suggestions how to remove the cursor from any text fields after POST validation fails?
would this work?
$('form').submit(function () {
if (!$('form').valid()) {
$('input').blur();
}
});

Checked value disappear after post back

I am using below tutorial to create image check box
enter link description here
it works properly but once page post back it lose the checked element and cannot retrieve it .
is there any solution for this issue?
This is absolute normal if you not save the post back somewhere and then render again the controls with the one that is selected with that class active, the rest controls with out that class...
See the javascript code from your page:
$(function () {
$('.btn-radio').click(function(e) {
$('.btn-radio').not(this).removeClass('active')
.siblings('input').prop('checked',false)
.siblings('.img-radio').css('opacity','0.5');
$(this).addClass('active')
.siblings('input').prop('checked',true)
.siblings('.img-radio').css('opacity','1');
});
});
The selected have the active class !, so after the post back, save the user selection and render the selected control with that class.

How can I grab a textfield value in Ext.Net?

I know there's a lot of information on this, but mine doesn't seem to be working out so well. I have a form that's created in C# in a form panel. My textfields are created like below:
Ext.Net.Panel panel = new Ext.Net.Panel();
Field field = null;
field = new TextField();
field.Name = "FieldTitle";
field.ID = "FieldID";
panel.Add(field);
this.searchform.Add(panel);
this.searchform.Add(new Ext.Net.Button()
{
Text = "Search",
Handler = "getID();"
});
When the search button is hit, then a JavaScript function is called which performs a store reload:
Ext.getCmp("#Gridpanel").getStore().reload({});
On the reload, I want to read the form fields and use the text for another part of the code. However, the below code doesn't seem to be working:
if(X.isAjaxRequest){
var ctrl = X.GetCmp<TextField>("FieldID");
string value = ctrl.Value.ToString();
}
I can get inside the 'if' statement, but ctrl comes back as null. Is there something else I need to include to grab the text field data?
EDIT
So I'm realizing that I'll have to pass an array of the search field ID's to a JavaScript function, then send a dataset back to the server side in order to implement the search. Just to throw it out there, is there a way to dynamically create controls (ie; a TextField) in C# and then get the value from those controls after an event is fired (ie; a button click)?
You can try to get the textfield using
Ext.getCmp("#FieldID") or X.getCmp("#FieldID"). FieldID is the client ID for TextField.
Use developer Tools to check the ID for the TextField

Highlight selected text and save it

I am interested in saving text when user selects any text anywhere on a web page that text has to be highlighted and has to save that text as a string in C#.
when same user saw same page next time text has to be highlighted as done previously by him.
If anyone knows a simple elegant way to do this I would really appreciate it, but I'll take any solution at this point. Even if you can point me in the right directions that would be appreciated.
Thanks in advance.
You need to write service WCF or Webservice in server side that will receive userId and text and save it into database.
[WebMethod(Description = "Save Text")]
public string Savetext(int userId ,string text)
{
}
Second method will retrive the text from daatabase by user id
[[WebMethod(Description = "Get text")]
public string GetText(int userId)
{}
In client side do invokation using Ajax calls (Jquery)
Use this to get selected text from page: http://mark.koli.ch/2009/09/use-javascript-and-jquery-to-get-user-selected-text.html
Then in mouseup event copy it to some HiddenField. Now you need a button or maybe AJAX call in mouseup so you can send it to server. On the server side save it to DB along with UserID and page address or ID.
On the next visit of this user to this page check in DB for entry. If it exist put the text in some hidden field. Then using jQuery get that text clientside, find it on page (using regex or something) and select it. You should remember to disregard any HTML markup while finding the text which can be tricky...
That is general way I would take to do this.
you can do that by capturing the selected text and send it via ajax call to your database.
check this example to know haw you can capture the selected text.
If you use jquerythen you will use select() function to capture the selected text
<textarea id="txt"></textarea>
<script>
$(document).ready(function(){
$('textarea').select(function()
{
var selectedText=window.getSelection();
//here put the ajax call to your webservice
});
});
</script>

Javascript added input control on .net postback

What I'm trying to achieve/plan, is whereby a page loads with a set of inputs, e.g. TextBox, Radio List etc. Taking TextBox as an example, there is a button for the user to "Add" another textbox to the page (in the same group), e.g. Member1, Member2, Member3 etc etc.
Two questions:
I could add these with Javascript, however the resultant "save" on postback would not get these inputs? If so, how?
The form needs to work without Javascript as well, so postback to dad another control is fine, however if I click the "add" button again, it will only ever add one control.
protected void btnAdd_OnClick(object sender, EventArgs e)
{
holder.Controls.Add(new TextBox { ID = "txtControl1" });
}
You can access the dynamic controls in the postback by name, using the following syntax "Page.Request.Form[""].ToString();". This uses the "name" attribute, not the "id" attribute.
I guess you can have one of these scenarios :
1- to save any new control ( textbox ) data in a session variable .. for example save name and value in which when any post back you can draw then again from this variable
2- If the only post back done from Add button you can do its function without doing post back as in this example http://msdn.microsoft.com/en-us/library/ms178210.aspx

Categories

Resources