C# - Get Variables From JavaScript To (MVC)
Mar 6, 2010
I'm using ASP.NET MVC (I'm really new to both asp.net and the asp.net mvc type projects, but trying hard to learn).
I've set up MVC with a controller so that it runs a C#.net method which;
queries an mssql db
converts it to json
returns the json string
It's called from the javascript by requesting an url with a parameter. But what I need now is for the C# part to read two integer variables from the javascript. What would be the best way to do that, and does anyone have any good examples/code that I could look at?
View 2 Replies
Similar Messages:
Jan 2, 2010
I have this code in javascript: var x = e.mapX; It gets the X-coordinate of a map. What I want to do is that I want to store this into a c# variable. I have a class named Test with an integer property X. I want to store var x into X. In the codebehind, I have this on the Page_Load: Test test = new Test(); Then I am trying this on the javascript code: var x = e.mapX;
View 16 Replies
Nov 10, 2010
I want to assign array of photos to imagearray but the following script is not working. i cant able to access variables a,i,cnlink etc in new fadeSlideShow() .how to access this outside the function and assign it to imagearray
<script type="text/javascript">
var i; var a; var cnLink; var cn;var cnSplit;
var photos = new Array();
var photoslink = new Array();
function x() {
a = document.getElementById('HiddenField4').value;
cnLink = document.getElementById('hdnLink').value;
cn = document.getElementById('HiddenField3').value;
cnSplit = cnLink.split(';');
while (i < cn) {
photoslink[i] = cnSplit[i];
photos[i] = b[i];
i++;
}
}
var mygallery2 = new fadeSlideShow({
wrapperid: "fadeshow2",
dimensions: [568, 313],
imagearray: [
photos
//<--array of images!
],
displaymode: { type: 'auto', pause: 2500, cycles: 0, wraparound: false },
persist: false, //remember last viewed slide and recall within same session?
fadeduration: 500, //transition duration (milliseconds)
descreveal: "always",
togglerid: "fadeshow2toggler"
})
</script>
View 1 Replies
Jan 2, 2012
I have a webpage in which I declared a variable in my code-behind as:
Code : Private ok As New HiddenField
I have a javascript function that sets this variable to either "T" or "F". However, I have a server-side button control that in the click() event, it checks the "ok" variable like this:
Code:
If ok.Value = "T" Then
FormatFields()
End If
The javascript function initializes the "ok" variable to "T". It goes thru a series of field edits. When a field doesn't pass the edit, it sets the "ok" variable to "F". Either way, this variable has a value. When the code-behind event above checks the "ok" variable, it's value is "".
View 1 Replies
Jan 10, 2011
I am calling a javascript function from .cs file which is as below:
private string CallValuesScript()
{
StringBuilder sb = new StringBuilder();
sb.AppendLine("$(document).ready(function() {");
sb.AppendLine("DisplayValues();");
sb.AppendLine(" });");
return sb.ToString();
}
I have two integers declared at class level private int ratingLinkId = 0 ;
private int ratingValue = 0;
how I can pass these two integer values to the function "DisplayValues();" ? I have the javascript function is aspx as below:
function DisplayRatings(id, count) {
//code
}
View 5 Replies
Jan 28, 2011
Just for an example, if I have three controls on a Master page, I would usually declare a variable for a control like this.
var elem = document.getElemntId('<%=control1.ClientID %>');
var elem2 = document.getElemntId('<%=control2.ClientID %>');
var elem3 = document.getElemntId('<%=control3.ClientID %>');
Can I do it in some form of concenation like:
[code]....
View 3 Replies
Oct 26, 2010
Is there a way to assign/pass/copy a javascript variable to a server side variable in C#? For the sake of argument, let's say that I was able to parse some JSON for variables that I want to store and assign them on the client (ie. var = FirstName and var = 25 and var = someDateTime, etc) .
View 4 Replies
Jan 28, 2011
I have a nested ListView (Master/Detail) and want to invoke a JavaScript function in the detail ItemTemplate so that this function can call a static method on the server site and post the field update. I need to include three data variables in the function call, two of which must come from the ListItem data. The JavaScript call to SaveAnswer that is contained in a list item embedded in the inner listview does not render properly. The code must pass three variables: ThisPAQID is a public variable from the codebehind. I could probably make it a hidden variable on this page. QuestionID is a variable from the current listitem and is contained in the table cell immediately preceeding the SaveAnswer method call.
The nested listview works great, and if I dummy the PAQID and QuestionID values in the function call (e.g. SaveAnswer(1,1, this.Value), it works fine.
<asp:ListView ID="lstQuestions" runat="server" OnItemDataBound="lstQuestions_ItemDataBound">
<LayoutTemplate>
<table>[code]....
When I put a breakpoint into this code in FireFox, the break never fires. Do I need an "OnBlur" tied to this code? Clearly I am not a JavaScript wizard.
View 1 Replies
Dec 18, 2010
I am working with Google maps api V3. I need to get the values of the getSouthWest & getNorthEast bounds of my map. To do this the 'bounds_changed' event needs to be fired in order to get the new values. This is all good, however, I need to access these values from outside the event and passed to a server side function (more specifically, I don't want to call my server side function every time the map bounds are changed).
My code is:
//Global
var sw, nw, Searchbounds;
function myFunc(){
google.maps.event.addListener(map, 'bounds_changed', function() {
Searchbounds = map.getBounds();
sw = Searchbounds.getSouthWest();
ne = Searchbounds.getNorthEast();
});
CallServerSideWebService(sw.lat(), ne.lng(), ne.lat(), ne.lng());
}
When executing this code I get the error message sw is undefined.
View 2 Replies
Mar 13, 2010
i am still stcuk with my project and unabale to perform calculation on my edited gridview..
here is my problem :
i have fields (f1,f2,f3, f4...) pulled from my sql data base table. into a gridview.
the "f4" field value is based on some calculation done on f1, f2 & f3 field values..
1- i need to have the same calculation done when i edit and update f1, f2 & f3 on my gridview...
more complicated..
2 -my calculation are based on a javascript function ...
a- how can i pass the fields values to the JavaScript variables...perform the calculation....then reassign back the result varibale to the f4 field ?? ..then update my gridview with the new calculation..
[code]....
View 6 Replies
Feb 7, 2011
For some reason it seems as though variables that I declare in javascript sometimes persist themselves across applications even when I do a response.redirect. I thought that a response.redirect would clear them out.
View 1 Replies
Aug 8, 2010
i am trying to collect 2 variables from one hyperlink, and use those variables in the page_load to set as session. but i don't know how to collect those 2 variables
such :
<a href="javascript:;" onclick="wsChangeColor('mainData', '#FF0000','#FFE4E1');return false;" title="Change color" id="red">1</a>
i would like to collect '#FF0000','#FFE4E1' or direct set '#FF0000','#FFE4E1' to string then send to pageload, how can i do this by only clicking on it ?
View 1 Replies
Jul 23, 2010
From what I understand, the id of the master on an ASP.NET page is "aspnetForm". I noticed today that for some reason in one of our pages it's now "form1". What would cause this change? Where should I look for the root cause of this naming change? We've got a lot of JavaScript variables that (sign) reference "aspnetForm" that are now broken.
View 1 Replies
Mar 5, 2011
whats the exact use of static variables in overall programming in .net and for asp.net...
Recently i went for the interview where interviewer asked me 2 question which i was not sure for the same..
whats the use of session object, i said sessions are the server side object, they are used when you want to store user specific data at server side, then he asked what if i want to use static variables for the same, i was mum, can anyone tell me how asp.net will behave if i store the user specific information in static variables.If i use cookies which are the best option to store the data at client side (not sensitive one), but what if user has disabled cookies on his machine, will my application would crash.
View 3 Replies
Jan 26, 2011
I cant figure out how to use the Application["myvar"] variable to store data for the application in asp.net 4.0 web app using c#. It say Application is not a known object and I can't for the life of me figure what to do a "using" on to expose it. I am in a static class at the time I cant use it. It seems to work in other units?
View 3 Replies
Apr 27, 2010
I have this function that I want to pass the IP and port to and check for a connection. It works fine if I put "127.0.0.1" in the tcpClnt.Connect line. But if I pass the IP2 as shown in the line commented out, it tells me No such host is found. It's like it thinks "IP2" is the host name. How can I pass a variable in there?
[Code]....
View 4 Replies
Mar 9, 2010
I know what they are and how they are used but i am not sure about their feasibility. Their use is always advised to be avoided. can some one explain me when they should be used and when not?
Aif i have a choice between static veriable and session for just storing an integer which one of these should i prefer??
View 3 Replies
Feb 13, 2011
I have some WCF services. These services run in ASP.NET. I want these services to be able to access a static variable. My problem is, I'm not sure where the appropriate server level storage mechanism is. I don't want to use the database because of speed. But, I want the static variables to stay in memory as long as possible. In fact, I'd like it to stay until I restart my server if it all possible.
View 2 Replies
Sep 8, 2010
I'm having some troubles using Session Variables as they are being used as Reference and I want to use them as value.
I got to this debuging my solution and I created something like:
DataTable dt =
(DataTable)HttpContext.Current.Session[
"SearchReturn-DataTableSchema"];
// Adding Rows of Data to DataTable dt
HttpContext.Current.Session["SearchReturn-DataTable"] = dt;
[Code]....
View 3 Replies
Feb 12, 2011
I am trying to use QueryStrings from my C# file in my ASPX file:
<asp:Button ID="LinkButtonDetails" runat="server" Text="DETAILS"
PostBackUrl='<%# string.Format("~/projectdetails.aspx?guid=<%= id%>
&name=<%= name%>
&role=<%= company_role%>
&member=<%= mem_id%>
&company={0}
&project={1}&id={2}", Eval("CompanyID"), Eval("ProjectName"), Eval("ProjectID")) %>' />
View 2 Replies
Jul 21, 2010
[Code]....
I have this VB ASP.NET sql data source that calls a stored procedure.
I also on the same page have a custom html form.
What I need to do is asign the form values the values of the database entries.
So something like:
UsernameFormField.Value = DatabaseParameter "username".ToString
View 13 Replies
Oct 12, 2010
why I couldn't get the variable from the URL.
<meta property="og:title" content="<% Response.Write(Request.QueryString["title"]); %>"/>
For some reason the code, <% Response.Write(Request.QueryString["title"]); %>, does not retrieve the data in this case. It works fine if I put it in the title tag though.
View 12 Replies
May 16, 2010
This question actually refers to a classic ASP page I'm working on, but I'm assuming that app variables work the same in both ASP and ASP.NET Let's say we have a bunch of websites, owned by different people. The sites are all different, but the common theme is they are car enthusiast websites. Each of these websites has their own unique index page (of course), but also "common" pages, which are pages shared by all the websites.
One of the common pages, checks for the value of an application variable, which may or may not exist. For example, lets call this page luxurycars.asp, which is a simple page that shows the top 10 luxury cars of this year. This common luxury car page will pull and use the app variable like so:
[CODE]
Dim SiteOwner
SiteOwner = Application("OwnerName")
Response.Write("This site is managed by " & SiteOwner)
[/CODE]
This app variable is set uniquely in each clients index.asp page like so:
[CODE]
Application("OwnerName") = "John Doe"
[/CODE]
Will this work? I just started learning classic ASP (for my job), and I'm reading that application variables are universal and only one copy of the variable will exist. So does this mean if John Doe sets Application("OwnerName") to "John Doe" in HIS index.asp page, will everyone that visits the common luxury car page see John Doe's name? Regardless of whether they got to that page via John Doe's page or someone elses? And if so would using a Session variable instead solve this problem? Sorry if this sounds confusing, let me know if I need to re-word it or give more detail...
View 2 Replies
Jan 17, 2011
I want pass the current page variables to next page and further also.
How to do this?
I was able to handle this to next page by previous page variable property but not further.
View 3 Replies
Apr 4, 2011
This is my first time working on a secure website. It's for a pet project I have.
For security purposes, where is it best to store information like SQL connection strings, database encryption keys, etc? Is it better to use web.config, store them in a class that accesses a database (like dataBaseHelper.cs or something), or somewhere else?
I intend to obtain an SSL cert as well. When communicating with the database, should I always use the secure connection?
View 2 Replies