<script type="text/javascript">
function Incrementer()
{
debugger;
var txtBox = document.getElementById('MainContent_TextBox1').value;
int i = parseInt(txtBox);
i = i + 1;
var v = i + "";
document.getElementById('MainContent_TextBox1').value = v;
alert(v);
}
</script>
<asp:TextBox ID="TextBox1" runat="server" Text="0"></asp:TextBox><br />
<asp:Button ID="Button1" runat="server" Text="Up" OnClientClick="Incrementer();"/>
<asp:Button ID="Button2" Text="Down" runat="server"/>
</asp:Content>
I am unable to increment the value in javascript....what is the problem?
There is no int in javascript.
Variables are always declared with var.
see fiddle: http://jsfiddle.net/HMC9V/
int i = parseInt(txtBox); this line is incorrect.
int doesn't used in Javascript for declaring variables.
It should be corrected to var i = parseInt(txtBox);
Related
I'm working in ASP.Net 4. I have the following within the body tag of my aspx:
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" EnablePageMethods="true" runat="server"/>
<script type="text/javascript">
function Process() {
var CHK = document.getElementById("<%=lstAffEmployees.ClientID%>");
var checkbox = CHK.getElementsByTagName("input");
var counter = 0;
for (var i = 0; i < checkbox.length; i++) {
if (checkbox[i].checked) {
counter++;
var Attorney = label[i].innerHTML;
var cutoff = Attorney.indexOf('[');
var cAttorney = Attorney.substring(0, cutoff - 1);
PageMethods.saveData(checkbox[i].value, cAttorney);
}
}
return true;
}
</script>
In my code-behind, I have:
[WebMethod]
public static void saveData(string attyNo, string attyName)
{
//mycode
}
In debugging, I get to the PageMethods call in the javascript, but then saveData in my code-behind is never called. I don't understand why not. Can anyone help?
I need to get a list of innerHTML strings from a website (for example facebook) to my .NET application.
Is there a way to get results from the following function into my application (i would put this data into a list) :
var data = new Array();
for(i=0; i<document.getElementsByClassName("class-name").length;i++)
data.push(document.getElementsByClassName("class-name")[i].innerHTML);
The code above outputs exactly the data i need, now my question is if it's possible to somehow get this data into my c# list?
This is how I'd like it to look :
var JS_DATA = data; //get the js array as a variable
static List<string> data = new List<string>(); //make a new list
foreach (string str in JS_DATA)
data.Add(String.Format("{0}", str)); //add the whole js array to the list
Here is an example:
see hidden Field array_store
Client side:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
var array_store;
window.onload = function () {
array_store = document.getElementById("array_store");
document.getElementById("array_disp").innerHTML = array_store.value;
};
function UpdateArray() {
var arr;
if (array_store.value == "") {
arr = new Array();
} else {
arr = array_store.value.split(",");
}
arr.push((arr.length + 1).toString());
array_store.value = arr.join(",");
};
</script>
</head>
<body>
<form id="form1" runat="server">
<span id="array_disp"></span>
<br />
<asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClientClick="UpdateArray()" />
<input type="hidden" id="array_store" name = "ArrayStore" value = '<%=this.ArrayStore %>' />
</form>
</body>
</html>
C#:
protected string ArrayStore = "";
protected void Page_Load(object sender, EventArgs e)
{
this.ArrayStore = Request.Form["ArrayStore"];
}
Here is the script that I am using for opening a new tab and it's working without using an update panel:
<script type="text/javascript">
function openInNewTab() {
window.document.forms[0].target = '_blank';
setTimeout(function () { window.document.forms[0].target = ''; }, 0);
}
This is my .aspx page: and i want to use it with update panel please help
<asp:ScriptManager ID="ScriptManager1" runat="server"
</asp:ScriptManager>
<asp:UpdatePanel runat="server">
<ContentTemplate>
<asp:Button ID="btnAssign" runat="server" Text="Assign" OnClientClick="SetTarget();" OnClick="btnAssign_Click"/>
</ContentTemplate>
</asp:UpdatePanel >
i want to use it with update panel please help me if there any solution
You code would run fine, if you would have noticed that your Javascript code has a syntax error. You are missing a closing } to define your function. Without it you are receving an unexpected end of input error.
In addition you will not open a new tab until you actually submit your form.
This code will work:
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
<script>
function SetTarget() {
document.forms[0].target = "_blank";
console.log("Foo");
document.forms[0].submit();
}
</script>
<asp:UpdatePanel runat="server">
<ContentTemplate>
<asp:Button ID="btnAssign" runat="server" Text="Assign" OnClientClick="SetTarget();" />
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>
You can use the below script. It will work for you.
<script language="javascript">
function SetTarget() {
document.forms[0].target = "_blank";
window.open(this.href);
alert("hello");
return false;
}
</script>
do let me know in case you required any more help.
Now i got solution by using a script and onclient click event
<script language="javascript">
function PopupHistory(url) {
var width = 550;
var height = 300;
var left = (screen.width - width) / 2;
var top = (screen.height - height) / 2;
var params = 'width=' + width + ', height=' + height;
params += ', top=' + top + ', left=' + left;
params += ', directories=no';
params += ', location=no';
params += ', menubar=no';
params += ', resizable=no';
params += ', scrollbars=no';
params += ', status=no';
params += ', toolbar=no';
newwin = window.open(url, 'windowname5', params);
if (window.focus) { newwin.focus() }
return false
}
</script>
on button event
<asp:Button ID="btnUnAssign" runat="server" Text="UnAssign" OnClientClick="return PopupHistory('/PatientAssignment/PatientUnAssign.aspx')" OnClick="btnUnAssign_Click" />
I got a silly question just as the question stated,the failed code shown below:
<script type="text/javascript">
function HISenlarge(id) {
var parent = id;
document.getElementById('HiddenField1').value = parent;
}
</script>
HTML:
<button type="button" id="kkkk" onclick="HISenlarge(this.id)"></button>
<asp:HiddenField ID="HiddenField1" runat="server" value=""/>
VBcode
Protected Sub CommentButton_Click(sender As Object, e As EventArgs) Handles CommentButton.Click
Dim c_id As String
c_id = HiddenField1.Value.ToString
document.getElementById('HiddenField1').value = parent;
This is not a HTML for the HiddenField1.So you should reference it by its ClientID
document.getElementById('<%=HiddenField1.ClientID %>').value= parent;
I am trying to get a value from a textbox so that that I can rotate an Image using jQuery
<script src="Scripts/jQueryRotate.2.2.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
var angle = $("input:TextBox1").val();
$("#needle").rotate(angle);
alert(angle);
});
</script>
And I'm populating the textbox as follows
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
WeatherLibrary.WeatherData wLib = new WeatherLibrary.WeatherData();
double dataLatest;
string sensorName;
sensorName = "umtAdjWinDir";
double dir = wLib.GetLatestData(sensorName).Value;
dir = Math.Round(dir, 0);
TextBox1.Text = dir.ToString();
}
</script>
TextBox1 is the the id of the textbox
<asp:TextBox ID="TextBox1" runat="server" ReadOnly="True"></asp:TextBox>
The alert I have given says undefined and the image never gets rotated.
Try
var angle = $("#TextBox1").val();
OR
var angle = $("#<%= TextBox1.ClientID %>").val();
If TextBox1 is the id of the input element you can use var angle = $("#TextBox1").val(); to get the value form the textbox
Try using :
var angle = $('#<%=TextBox1.ClientID%>').val();
try
var angle = $("input#TextBox1").val();
assuming you have an input with id="TextBox1"
I think not sure it may be a problem of master page or user control.
<script src="Scripts/jQueryRotate.2.2.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
var angle = $("#TextBox1").val();
$("#needle").rotate(angle);
alert(angle);
});
</script>
Supposed to be
var angle = $("input[id*='TextBox1']").val(); // For ID
var angle = $("input.TextBox1").val(); // For class
var angle = $("[id*='TextBox1']").val(); // For ID this is sufficient
Need to use attribute ends with $ or attribute contains selector * if you are using ASP.NET controls with runat="server" attribute
$("#TextBox1").val() this code will help u out to get the textbox value..