Tabbing not picking up onclick event - c#

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")

Related

Need to access client-side label value (Angular directive) on postback...getting {{radioModel || 'null'}} every time

Following the code on Angular UI, I was able to integrate the Radio & Uncheckable Radio buttons into my solution. I have 2 radio buttons, both of which can be toggled and then I have an asp:Label to display the output.
I would prefer setting the label's visibility to false in the long run but for now it is visible.
By setting the asp:Label Text property to {{radioModel || 'null'}} I can see the value of the selected radio button on the client side page and viewing the page's source. Problem is, when I post back to the server, specifically attempting to store the value in a database, I only see the {{radioModel || 'null'}} declaration, rather than the value of my selection.
I'm new to Angular but the idea seemed pretty straight forward. I just need to figure out how to retain the label control value when storing to a database.
Here is my asp.net code with the angular declaration within the label.
<div ng-controller="EmployeeTypeChoiceRadios">
<div class="btn-group">
<label class="btn btn-primary" ng-model="radioModel" btn-radio="'Employee'">Employee</label>
<label class="btn btn-primary" ng-model="radioModel" btn-radio="'Contractor'">Contractor</label>
<!-- Pull Results from this label on form submit -->
<asp:Label ID="EmployeeTypeChoiceLabel" runat="server" Visible="false" Text="{{radioModel || 'null'}}" />
</div>
</div>
Here is how I have my JavaScript set up. I think this has more to do with the default radio selection however
// New Form - Employee Type Employee/Contractor - Radio Button
var EmployeeTypeChoiceRadios = function ($scope) {
$scope.radioModel = 'Employee';
$scope.checkModel = {
employee: true,
contractor: false
};
};
Finally, here is how I am collecting the label's data - Really just adding to a stored procedure parameter.
newformsqlCmd.Parameters.AddWithValue("#empEmpType", EmployeeTypeChoiceLabel.Text); // Employee Type choice
For the record, I've also tried basic HTML inputs (Labels) and to get their values like this..
BasicHtmlInputLabel.Value
I appreciate it in advance.
ngModel is only supported on the following elements:
input
text
checkbox
radio
number
email
url
date
dateTimeLocal
time
month
week
select
textarea
Using one of them instead of a label should solve the problem.

Open a new window with Same session using jquery/C# Razor

I am trying to open a new window with same session as the current one. I wrote some code below but its no luck yet.
For example lets say i have a form with a label (Name), textbox (where the text goes in)
and a button when pressed takes me to a new window.
If i press the button it should open a new window with the same form elements and text in the textbox if it was put in before.
Also please note the new window must be opened as a new tab in the browser with the same state and same elements as in the previous browsers.
Anyone got an idea on this (using razor view engine or jquery/javascript) ? Thanks in advance.
<label for="Name">Name</label>
<input type="textbox" value="nothing" id="text" />
<input type="button" value="press me" id="submitButton" />
$(document).ready(function()
{
$('#submitButton').click(function()
{
var currentUrl=document.URL;
window.open(currentUrl,"newWindow",300);
event.preventDefault();
});
});
You may be able to accomplish this by using modals instead of popup windows. Jquery UI has built in modal support: http://jqueryui.com/dialog/
The advantage to this approach is that no data needs to be passed into a separate page. Your modal code would look something like this, with jQuery Dialog. This would go on the same page as your initial inputs:
<div id="dialog" title="Basic dialog">
<input type="text" id="popupText" name="popupText" />
</div>
and your click event would modified update the modal input and show the modal:
$(document).ready(function(event)
{
$('#submitButton').click(function()
{
$("#popupText").val($("#text").val());
$("#dialog").dialog();
event.preventDefault();
});
});
This could definitely be cleaned up but I believe it'll do what you need pretty simply. The dialog can contain any html elements, so you can add a separate form if necessary.

Button always trigger upon pressing enter in textbox

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

How to show a Panel with animation using RegisterStartupScript and jquery in c#?

I am trying to show a panel from the code behind with an animation. The panel does show but with no animation, this is the line that is not working:
Page.ClientScript.RegisterStartupScript(this.GetType(), "ScriptBlock", "$(document).ready(function(){$('#" + pUserActions.ClientID + "').show(\"slow\" );});", true);
Any help is appreciated.
The problem is that afer the PostBack the Panel (or div) is already visible, and .show() does not work if the element is already visible. Try this for example:
html:
<div style="background-color:red; width:100px; height:100px"></div>
<input type="button" value="Show" id="btnShow" />
<input type="button" value="Hide" id="btnHide" />
js:
$("#btnShow").on("click",function(){$("div").show("slow");});
$("#btnHide").on("click",function(){$("div").hide("slow");});
Fiddle: http://jsfiddle.net/hescano/VY9jt/
As you can tell, if you press the Show button when the div is visible nothing will happen. Try having the panel visible before calling the server side script and you will see what I mean. Note that the Visible property of the Panel control will not work, because this removes the element from the DOM altogether.

How to assign values before unload event in asp.net

Hi i want to assign two string values from popup window back to parent window which open the popup window.
for which i take two hidden field both in parent and child window as runat server,
and on button click event i assing these hidden field some text value
/*(Hidden field 1 ->)*/ c_value.Value = Treeview.SelectedNode.Parent.Value;
/*(Hidden field 2 ->)*/ c_text.Value = "File selected";
and on body unload event i assign these value to parent's hidden field through javascipt
(HTML)
<script>
function assgin()
{
window.opener.document.getElementById("ctl00_ContentPlaceHolder1_p_value").value = document.getElementById('c_value').value;
window.opener.document.getElementById('ctl00_ContentPlaceHolder1_p_text').value = document.getElementById('c_text').value;
</script>
<body onunload="assign()">
but when i try to get these value on parent form it is showing empty.
i not understand why these values become empty may be due to onunload event, if this is the reason then tell me on which event i assign these values to parent form .i want to assign these values before closing child window.
Maybe your problem is due to a typo of "assgin()" function. But if not, here is a small example that works for me. NOTE: you can't test this on a local disk, because in that case the browser will prevent access to window.opener for security reasons.
parent.html
<input type="button" onclick="window.open('popup.html','My Popup')" value="Open popup" />
<br/>
Result from popup: <input type="text" id="result" />
popup.html
<script>
function assign() {
window.opener.document.getElementById("result").value = document.getElementById("mystring").value;
}
</script>
<body onunload="assign()">
Enter string and close the popup: <input type="text" id="mystring" />
<body>

Categories

Resources