C# - Hidden Variable Vs Server Variable Accessing On Client Side In Javascript

Jul 14, 2010

I'm evaluating two options of accessing a server side data on client side. Little bit confused about the efficiency or may be you can call it as finding best approach to do it.

I need to access a server side data may be an integer value in javascript on client side. I know about two options to do it.Create a public variable or property on server side and set it to javascript variable on client side as below:

var value = eval(<% =value %>);

Create a asp hidden variable and set value in this hidden variable from server side and access it through javascript using document.getElementById().

Which is the best approach and what are the pros and cons?

View 1 Replies


Similar Messages:

Access Server Side Variable On Client Side And Vice Versa And JavaScript?

Dec 9, 2010

I have a requirement of adding server side variables in client side and other way round. Because I need to set a value from client side using javascript and access the same in code behind page.

I have to use C#.Net and JavaScript.

View 2 Replies

Javascript - Get The Value Of Client Side Variable In Server Side?

Mar 24, 2011

I want to ask how to get the value of var title :

From this code :

protected void btnSubmit_Click(object sender, EventArgs e)
{
string script = "var title = $('.rsApt').attr('title');";
ClientScript.RegisterStartupScript(GetType(),"popup", script, true);
}

View 2 Replies

Web Forms :: Adding Data From Text Box To Hidden Variable On Client Side

Feb 25, 2012

I have a textbox where data will be entered by user without any postback. I need to add the data to a variable or any hidden variable or i need to store data from all the controls on th epage in which user entered to a variable this controls in which user enters the data becomes visible on button click i mean a post back happen...

View 1 Replies

Web Forms :: Setting Hidden Value Server Side And Accessing On Client Side?

Jul 19, 2010

I am trying to set a hidden type value to x on Server Side and then access it with Javascript. I have tried multiple ways to accomplish this.

At the basic level this is what I am trying to do.

Aspx page
<asp:HiddenField ID="HidRowNumber" runat="server" />
CS Page
In IsPostBack
HidRowNumber.Value = EFileRowNumber.Text;
Javscript
var status = document.getElementById("<%= HidRowNumber.ClientID %>").value;

When I am debugin it say it HidRowNumber's Value has changed to x but when I access the value with JS it always returns ''.

View 23 Replies

Server Side Control Hidden - Possible To Read Values Client Side

Jan 30, 2010

I've got two textboxes running server side and have their visibility turned off. I'm using a couple of ASP.NET controls which require the textboxes to exist. However, I am filling them from the code behind and would not like the user to see this. Can the user turn the visibility on and see the values entered in the text box? I tried using FireBug, and I couldn't seem to select the visibility option in order to edit it. However, I'm quite new to Firebug, so there may be another way? Or does running it server side mean that the client can't ever view the contents of the textbox?

View 1 Replies

Web Forms :: Accessing Javascript Variable In Label Control?

Jun 11, 2010

I have a javascript variable in the script tag. I am assigning a value to that variable and I want the same value to be assigned to the label control e.g. consider the sample code below :

<body><script type="text/javascript">
var a=window.opener.parent.document.getElementById('description').DataValue;
</script>
<
asp:Label
ID="lblSubject"
runat="server"
Width="142px"
Font-Bold="True"
Font-Size="10pt"
Font-Names="Arial"
>SUBJECT</asp:Label>
</body>

How do I assign the value of variable a to the label?

View 8 Replies

Javascript - User Control With Client + Server Side CustomValidation; Wrong Client Side Validator Is Picked

Nov 23, 2010

I have a user control which contains a CustomValidator which is used according to whether a RadioButton is checked or not (there are several RadioButtons, I'm only showing the relevant one)

<asp:RadioButton runat="Server" ID="RadioBetween" GroupName="DateGroup" CssClass="date_group_options_control_radio" />
[code]...

There is some client + server side validation code (the server side code does exactly the same thing and is skipped for brevity)

<script type="text/javascript">
function ValidateDateFields_Client(source, args) [code]...

There are two instances of this control in the page. When running the client side version it hits the wrong one (the version of the control which is disabled). You can see from the generated HTML both are correctly specified. I'm not sure how .NET works out which clientside function to call given they both have the same name.

<script type="text/javascript">
//<![CDATA[
var ctl00_MCPH1_QueryTextValidator = document.all ? document.all["ctl00_MCPH1_QueryTextValidator"] : document.getElementById("ctl00_MCPH1_QueryTextValidator");

[code]...
Do i need to add something in to scope it? What's the best way to achieve this? If I disable the loading of the second control everything works fine.

View 1 Replies

JQuery :: Grab A Global Variable Or Session Or View State Variable In The Javascript?

Dec 9, 2010

can we grab a global variable or Session or View State variable in the javascript or using jquery?

View 2 Replies

Accessing Client - Side Generated Table Rows Through Server - Side

Feb 23, 2010

The idea is that a pure html table will be generated on the client side. (using jQuery to add dynamic new rows to the table when the user clicks a button). These rows contain textboxes, dropdownlists, checkboxes and other input controls. When the user clicks a button, a PostBack is triggered in which I need to access this data from the table on server side, validate it and perform other actions on it.

I'm able to perform the client side and access the table data on server side by adding runat="server" to the table tag. However, I only see the initial table rows (not the ones added through JavaScript) and I have troubles retrieving the different inputs from the rows. put me in the right direction?? Or someone offering a better solution to the problem?

View 2 Replies

Javascript - Getting Null Value Of The Hidden Field At Server Side

Feb 18, 2011

I am calling a Java-script function, in that i am passing the value of hidden field, that hidden field i want to use at server-side, but the value of hidden field is null.

Client Side function

function getDetails()
{
document.forms[0].HdnNode.value=tree_selected_id; //HTML Hidden Field.
str="Cmp_12";
str_array=str.split("_");
var str_array1=str_array[0];
var str_array2=str_array[1];
document.getElementById("<%=HiddenNodeId.ClientId %>").value=str_array1;
document.getElementById("<%=HiddenTreeId.ClientId %>").value=str_array2;
}

Server Side Function

Public Sub InsertNodes(ByVal NodeId As String)
Dim objErrorObj As New ErrorObj
Dim ParentID As String
ParentID = HiddenNodeParent.Value
NodeId = HiddenNodeId.Value
Dim NodeIDTree As String
NodeIDTree = HiddenTreeId.Value
End Sub

View 1 Replies

C# - How To Execute Server Side Code Just Before The Session Variable Expires

Oct 7, 2010

In my asp.net website I am creating a session upon user login and I would like to perform some operations in the database just before this session will expire.I am having problem in determining where should I write code and how will I know the session is going to expire.

I am not sure if 'session_end' event of 'Global.asax' suits my requirements as the session I want to check is created manually(not a browser instance).

View 1 Replies

Web Forms :: Accessing Client-side Table Rows On Server?

Jul 23, 2010

I have a table that the user can add rows to through javascript by clicking on a "add rows button". In each row there are two columns one with a dropdown list and the other a text box. The dropdown list is populated with data through a sub on server side code.I need to be able to insert the data from each row into a table but I'm unable to do this. I clicked on my "add rows button" to add several rows and then did a test to see how many rows the table was returning on the server side and it did not include the five rows I added .. only the header row.If there is a better way to allow users to dynamically add rows to a table and then access the dynamically created table on the server then I'm all ears!

View 3 Replies

JavaScript - Exposing Server-side State Through Client-side Controls

Feb 11, 2011

I have a list of items on an ASP.net page. That list is selectable in that whenever the user clicks on one, the page does a postback and the server code stores the index or some unique identifier of the picture in a ViewState property indicating that it is currently selected.

I would like to minimize the load on the server and therefore I would like to store the index or unique identifier representing the image in some way on the client side. The best way I can think to do this is to store said information in a hidden field ), however I had two questions about this before I go crazy:

Is this a security risk in any way, shape or form (i.e., exposing implementation details of the page)?
Is there a better/best way to do this that is more industry-standard? Does ASP.net provide a framework to do this that is cleaner than my idea? Seems like this would be a fairly common requirement to me...

View 1 Replies

C# - Calling Server Side Function From Client Side JavaScript?

Sep 14, 2010

Possible Duplicates: how to call server side function from client side - asp.net Calling ASP.NET Code Behind function from Javascript Calling ASP.NET server side method via JQuery While loading an aspx page, how is it possible to call a server side method with the client side code?Can u show one example?

View 4 Replies

JavaScript - Pass Arguments From Client Side To Server Side?

Feb 11, 2011

I have two comboboxes and would like pass selected value and text to the server method (RadComboBoxItemsRequestedEventArgs) when the first combobox selected index changed.

Here is my code. But I am getting Javascript error message at this line. RadComboBox2.requestItems(item, false).

[code]....

View 1 Replies

JavaScript - Detecting Client-side DOM Changes Server-side - Is It Possible

Mar 7, 2010

I'm working on developing a custom control to select items from a predefined list. This is accomplished via 2 ASP.NET ListBox controls, with a few buttons to trigger the movement of ListItems from one ListBox to the other (lets call these ListBoxes lstSelected and lstDeselected).

This is easy enough to do in ASP.NET or JavaScript independently: I have both working. However, if modifications are made via JavaScript, ASP.NET retains no knowledge of this. Is there any way to register the creation of of options in a select tag without AJAX?

View 2 Replies

How To Convert Server Side Vb.net To Client Side Javascript

Mar 20, 2010

I've got a function I wrote quite some time ago that works fine, but I'd like to speed up the process and lessen server load by doing the same job in Javascript.I seem to be able to GET textbox values ok, but I can't seem to SET textbox values (I'm'-a JS noob). Can anyone lend a hand in converting my VB.NET code to it's JS equivalent?

Protected Sub txtSellingPrice_TextChanged(ByVal sender As Object, ByVal e As EventArgs) _
Handles txtSellingPrice.TextChanged
Dim SellingPrice As Double = Double.Parse(txtSellingPrice.Text.Replace("$", ""))
[code]...

View 2 Replies

Hidden Variable Getting Blank When Sending From One Page To Another?

Nov 9, 2010

There are two frames. In ASP page 1 that is being displayed in frame 1, we have a form with hidden variables. On some action this from is submitted to frame 2 with action as ASP page 2 (target = frame2, action = 'ASP Page 2') using POST method. But on ASP page 2 when we try to get Form's hidden variable via Request object, sometimes we get them correctly but sometimes they are blank. Generally, first or second time, they show some values but after that they go blank. This problem is seen in IE 7 only and has not been observed in any other version of IE or other browsers.

View 1 Replies

MVC :: Session Variable Versus Hidden Field?

Jun 8, 2010

I have an application that goes through a series of questions and I have a view that shows each question based on the ViewData.

I would like to store the QuestionID (the view uses this to determine which question to show), but I'm curious if I should be storing the CurrentQuestionID in the Session or as a hidden field?

I am sure this is pretty common and I was curious what the conventions/best practices were for this sort of thing.

View 2 Replies

Assign Business Entity To Hidden Variable?

Jun 26, 2010

Question. Say for example if i have a business entity -> Customer, which has customerId, customerName and customerType. I have created an asp:Hidden Variable hdnCustomer to runat="server"

If i wanted to serialize the value of the customer business entity (in the code behind) to the hdnCustomer then how would i do that?

// Psudo code
Collection customerList = new Collection();
customerList = BusinessAccess.GetCustomerList();
hdnCustomer = serialize and assign the value of 'customerList' to hdnCustomer;
...
...
// Later on a select index change of one of the drop down lists

inside the event handler for the drop down list

{
Collection customerList = new Collection();
customerList = deserialize the value from hdnCustomer
int a = Convert.ToInt32(ddlDropDown.SelectedValue);
foreach(a in customerList)
{
// Do something
}
}

View 2 Replies

Using Session Variable Instead Of Hidden Fields In Aspx Pages?

Feb 22, 2010

I would love to use hidden field value but I think I am missing something to do.

Since every page refresh or staying a little bir longer on the page, the value is missing.

[URL]

How can i do the this cookiles suff above...?

I use hidden value to keep the url to redirect to next page. May be i sould not keen on using hidden value, session variables are better?

View 1 Replies

Using Hidden Input Variable In The Base Class To Persist Value Across Postbacks?

Jan 13, 2011

In my base class:

[code]....

In my user control that inherits from BaseUsercontrol The ascx has:

<asp:Button id="btnTest" runat="server" OnClick="OnButtonClick" />

Why can't I use the hidden input variable this way?

View 1 Replies

Forms Data Controls :: Passing Hidden Variable Value In DataNavigateUrlformatstring?

Jan 24, 2011

I am using ASP.NET 2.0 and C#. I have a gridview, which has a datanavigateurlformatstring, in which i am passing data in the gridview as querystrings.I have a hiddenvariable in the page. i would like to pass the hidden variable to the gridview in the datanavigateurlformatstring.Currently i have the gridview and hidden variable like this:

[Code]....

How to pass the hiddenfield value in the datanavigateurlformatstring?

View 3 Replies

AJAX :: Can Send An Object From Client-side JavaScript To Server-side Code Via AJAX

Mar 16, 2011

I know that I can receive an javascript object from the server via ASP.NET AJAX using Json. But I am not sure how can I send an javascript object from my client-side javascript to my server-side code. And if I can, how can I extract this object in my server-side code and access its members?

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved