Button always trigger upon pressing enter in textbox - c#

Kindly help me with this, i have a page with left side user control and right side user control. left side user control has two text box and 1 button, right side has 1 text box and 1 button.
Currenlty this error happen, When I put my curson either textbox1, textbox2 or textbox 3 and press enter button 1 always trigger, i want to trigger button 1 only if i put my cursor on textbox1 or textbox2 and press enter, button2 should be trigger if i put my cursor on textbox 3 and press enter.
kindly see the mock up picture - http://postimg.org/image/b1o8i8h3l/
thanks,,,,

You should add separate forms to your page, like this:
<form>
<input type="text" id="textbox1"/>
<input type="text" id="textbox2"/>
<button>Button 1</button>
</form>
<form>
<input type="text" id="textbox3"/>
<button>Button 2</button>
</form>

Maybe you could you use a bit of javascript. Perhaps use the onblur event on one of your textbox to bind the keypressEvent to the required button. Assuming the button is valid if there is text in the textbox

Related

Tabbing not picking up onclick event

Currently having an issue with attributes to my tag:
<InputText id="KeywordsInput" #bind-Value="product.Keywords" placeholder="Bike, Mountainbike, blue" onfocus="this.placeholder = ''" onfocusout="this.placeholder = 'Bike, Mountainbike, blue'" onclick="#ChangeAttributesVisibility" onblur="#ChangeAttributesVisibility"></InputText>
<p class="helpNote" hidden=#helpNoteHidden>Sepearte keywords with a comma</p>
This is a small snippet from my form. For clarification when I click on the textbox the placeholder disappears and the <p> tag should appear.When I click off the textbox the <p> tag disappear and (if text has not been input) the placeholder should return. This works perfectly when I click. But when I tab onto this textbox the placeholder disappear but the <p> tag does not appear. This means that when I leave the onblur event is called and it then appears - at the moment it shouldn't.
Is it possible to have both things happen in the onfocus event? (e.g. onfocus="this.placeholder = ''" & "#ChangeAttributesVisibility")

Click a Dropdown Menu Button using Watin

I am testing a website using Watin in the page there is dropdown menu button like if I find that button and click it clicks the entire button and selects the first Option in the menu but I want to click the V of the button to show the dropdown menu(div) and select the option from it the code I had tried to click the button
ff.Button(Find.By("aria-describedby", "x-auto-456")).FireEvent("onmouseover");
ff.Button(Find.By("aria-describedby", "x-auto-456")).FireEvent(" Onmousedown");
ff.Button(Find.By("aria-describedby", "x-auto-456")).Click();
the Button HTML
<button class="x-btn-text" style="position: relative; width: 16px;" type="button" tabindex="0" aria-describedby="x-auto-456">
Edit:
I had tried to find the co-ordinates of the Image in the button and then click it with the below code but its slightly not working kindly any one point me how to click the button and show the div Instead of selecting a option automatically,
NameValueCollection eventProps = new NameValueCollection();
eventProps.Add("clientY", "240");
eventProps.Add("clientX", "240");
ff.Button(Find.By("aria-describedby", "x-auto-456")).FireEvent("onClick",eventProps);
You are not finding the button correctly:
Button button = ff.Button(Find.ByClass("x-auto-457"));
You need to find the button by its class name. Be aware that will find the first <button> or <input type="button|submit|reset"> element with that class name. If you still aren't getting the correct button, check to see how many buttons on the page have x-auto-457 for a class attribute value.

Assign textbox's value to another texbox without a botton

I want to know what is the best way to assign a value to textbox 2 instantly as the user write this value in textbox 1 ie. Directly showing what the user is entering in textbox1 also in textbox2 at the same. I'm using MVC5 aspx pages..
Any help is highly appreciated. Thanks in advance
Add a onkeyup event listener to your first element(Whenever a key is pressed, the value in first textbox is also entered in second.). Then call the function like
function enterAmt(ev) {
document.getElementById('amt2').value = ev.value;
}
You have to use javascript or jquery for it, suppose you have two textboxes.
HTML:
<input type="text" id="txtBox1"/>
<input type="text" id="txtBox2"/>
You have to write keyup event for the textbox and copy its value in second.
JQUERY:
$("#txtBox1").on('keyup', function () {
$("#txtBox2").val($(this).val())
})
Here you can find the solution to the absolutely same question: Textbox onchange in ASP.NET

Windows form application clicking an "onclick=return"

So im trying to make an script that does the BFH (in a game) auto but when it clicks on the sumbit button the webbrowser opens up an confirm box (code element inspecting showed down). So how do i make it so my application clicks the ok on the confirm box
The webbrowser opens up a box and the application has to click the ok button
Sorry if i explain it strange its because my english isnt that great
this is the button it clicks
<input class="submit" type="submit"
onclick="return verifyTransport('Are you sure you want to transport €…,000 to the team deposit?\nThe trip will take 25 minutes.');"
value="Transport € 5,000,000"
name="dr_transport_money"></input>
Example of what it shows(cant show the real one can only do that once a day):
Try This:
private IWebElement element;
element = driver.FindElement(By.XPath("//input[#name='dr_transport_money']"));
element.Submit();
driver.SwitchTo().Alert().Accept();

DefaultButton when using masterpages ASP.net

I am using masterpage in my solution. In that masterpage there is a imagebutton named "Save" using as the saving option for all my pages, which is set as Defaultbutton in masterpage. The problem is that, in one of my page i have a textchanged event which i want to work when pressing "Enter" key. But when i press "Enter" key "Save" function works after the textchanged event. I dont want to happen "Save" function on "Enter" key press. I don't want there to be any default button on my page
You can set the button's UseSubmitBehavior = "false"
similar question is here Canceling the default submit button in ASP.NET
I think you have to prevent enter key while you are work in text-box
just put this function in ur page.
just add onkeydown event to ur text-box
<input type='text' onkeydown="return (event.keyCode!=13);" />
another one
this function need jquery
$('input').keypress(function(event) {
if (event.keyCode == 13) {
event.preventDefault();
}
});

Categories

Resources