Showing posts with label value. Show all posts
Showing posts with label value. Show all posts

Wednesday, March 28, 2012

Programmatically creating OpacityBehavior

How can I programmatically create a opacitybehavior and attach it to a control and set its opacity value ?

Following doesnt seem to work in both IE and firefox? I changed the order of initialize() in my following code, it still doesnt work.

function setOpacity()

{

varp_lightgreendiv =new Sys.UI.Control($('lightgreendiv'));

var a =new Sys.UI.OpacityBehavior() ;

a.set_value(0.1) ;

p_lightgreendiv.get_behaviors().add(a) ;

p_lightgreendiv.initialize() ;

a.initialize() ;

}

Thanks

Indo.

Hi,

I've answered to this threadhere.

Thanks it works! I dont know what i am doing wrong in my example.

~Indo.

Monday, March 26, 2012

Property value disappear on click with user control

Hi,

I have a user control which require input text boxes and a caclulate button. When I hit the recalculate button, lblMonth becomes blanks. Please see the code below and guide how to keep the lblMonth the value of lblMonth

============
<asp:UpdatePanel ID="upPanelSales" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Label ID="lblMonth" runat="server" Font-Bold="true" ForeColor="white" CssClass="heading" />
-- some text box controls
<asp:Button ID="btnReCalc" runat="server" Text="Recalc." CommandName="Calculate" CommandArgument="ReCalc" OnCommand="Calculate" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnReCalc" EventName="Command" />
</Triggers>
</asp:UpdatePanel
Code Behind
Private _MonthNameAs String

Public Property MonthName()As String
Get
Return _MonthName
End Get
Set(ByVal valueAs String)
_MonthName = value
End Set
End Property

Protected Sub Page_PreRender(ByVal senderAs Object,ByVal eAs System.EventArgs)Handles Me.PreRender
Me.lblMonth.Text = _MonthName
End Sub

Protected Sub Calculate(ByVal senderAs Object,ByVal eAs CommandEventArgs)
If e.CommandName ="Calculate"Then
Select Case e.CommandArgument
Case"ReCalc"
ReCalculate()
End Select
End If
End Sub

Main Page
=========

<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true" />
<Sales:Input ID="uc" runat="server" />
Code Behind

Sub Page_Load
uc.MonthName = Month1
End Sub

you probably want to do this in your main page code behind so it only gets set when the page loads the first time

Sub Page_Load

if not Page.IsPostBack Then
uc.MonthName = Month1
end if
End Sub


My main page contains 4 link button controls called Qtr1, Qtr2, Qtr3, Qtr4 and I want to change the month value based on user clicking on quarter links? The real problem is due to submit button inside the user control and partial page refresh has applied on this user control.


so you solved it? or you're still asking?

if those 4 links are outside of the updatepanel they will trigger a full post back and the data inside the update panel contents will be treated no differently than if they weren't inside an updatepanel.

if you click the the linkbutton inside the updatepanel the only thing that will happen is the data within the updatepanel will postback and the associated button event will fire. Only data within the updatepanel will post back to the server though. Data outside of the updatepanel will still appear to the server as the same data regardless of change on the client side...

Property value undefined after succesfull web service call

Hello,

hopefully I can explain my problem.

I started to create extended control with ajax control toolkit. Idea is, that I have textfield which works so

that it suggest values every time when user hits key. Like that --> http://www.google.com/webhp?complete=1&hl=en

Now in SearchTextBoxBehavior.js file I have two propertys, which one hold id for listbox which shows suggestions.
(I think in that google example, the control is span or div element.)


Ok, I have succesfully created event, which is occurred when user hits key in textfield. Webservice call is made in bold code line-->

1_onkeyup : function() {
23 var targetButton = $get(this._TargetButtonID);
4 var targetListBox = $get(this._TargetListBoxID);
5
6if(targetButton && targetListBox) {
7 targetButton.disabled =true;
8
9// unescape() convert′s a string to URL-encoded form10 var searchValue = unescape(this.get_element().value);
11
12if(searchValue !="") {
13// Set suggestion visible14 targetListBox.style.visibility ="visible";
15
16MyCompany.WebServices.MySearch.GetDataTableFromWebservice(searchValue,this._onSucceeded);
17 }
18else {
19// Set suggestion hidden when there is no search value inserted20 targetListBox.style.visibility ="hidden";
21 }
22 }
23
24 },
 
Web service call is succesfull, and returns into function:
 
1_onSucceeded : function(Result) {23var targetListBox = $get(this._TargetListBoxID);45var table = Sys.Preview.Data.DataTable.parseFromJson(Result);67...89}
 
Problem is, that in that _onSucceeded function, propertythis._TargetListBoxID is
undefined. In function, where I made web service call, the property was ok, and I could
make instance about control.
 

Hi,

you need to modify the context under which the callback is executed. This can be done with a delegate and the Function.createDelegate method:

MyCompany.WebServices.MySearch.GetDataTableFromWebservice(searchValue,Function.createDelegate(this, this._onSucceeded));



Hi,

it worked, thanks. :)


Yesterday evening I managed to circulate problem, with solution below.

1var inputParams =new Array();2inputParams[0] =this._TargetListBoxID;3inputParams[1] =this._TargetButtonID;4inputParams[2] =this._ListControlTextField;5inputParams[3] =this._ListControlValueField;67MyCompany.WebServices.MySearch.GetDataTableFromWebservice(searchValue,this._onSucceeded,this._onFailed, inputParams);

Hi,

yes, as your code shows, you're passing a context object as the last parameter to the proxy method. This is useful especially if you want to access only certain references in the callback and not the whole instance.


Hi All,

huygens...is there any way you can post your full code? I'm looking to do something similar with the toolkit. Would be greatly appreciated.

Saturday, March 24, 2012

question about ListSearch tool

Hi,I have a problem with ListSearch tool ,when i find the word in the list i need save this word in a variable but no value save in my variable how can do this ??!!!

when i use DropdownList.selectedItem or value my variable is null ,

protectedvoid DropDownlist1_SelectedIndexChanged(object sender,EventArgs e)

{

string Var = DropDownlist1.SelectedItem.ToString();

}

please help me...Tongue Tied

thanks

Have a look here:http://www.asp.net/learn/ajax-videos/video-142.aspx for how to use the ListSearch control.

-Damien


Thanks from your answer... i look this video but ...this can't help me because i need the value of selected item of DropDownList but when i return this value,it is null and the selected index= 0 how can solve this problemt ...Thanks


In this video if you return selected value of dropDownList, the value is 'Alfa' for all of your selection (Sample for ListSearch Ajax) and the selected index=0 for all of selection this problem create when i bind an array list to dataSource of DropDownList ,i delete ListSearch tool from my form but this problem dont solve how can solve it...??

question about the callback feature and scriptmanager

Hi,my application will have a textfield and a button (html control) and when the button is clicked, it will pass the textfield.value by calling a javascript function to the server side function and do something such as find the data in a database, after that it will return the result back to html page.

my question is, as far as I know I can use callback feature to do this, becuase what i need to do is register a page in the behind code. so the js function can call the registed function. However, as I know if use the scriptmanager and create a web serivce page with setting the class or specific methods as [scriptservice] attribute, then the js function can also call the code-behind function. therefore I wonder what is the different between those two feature. Hope someone can explain to me.

Ok, so you are using Callbacks instead of postbacks by using ICallBackHandler? Then you are also using MS AJAX? with ScriptManager?

You should only use one kind of AJAX. If you use only MS AJAX you won't have to use javascript to update your controls.

Wednesday, March 21, 2012

question on Ajax and .NET method

hi all,

is it possible to pass a javascript object (which has key value pairs) to a C# method through an Ajax call.

if yes,

can you please give me some sample code on how to refer to those key values in C# method?

Thanks in advaance

Sanjay

Using AJAX, you are making a call to the server. Your key value pair in Javascript is serialized in to string with some dilimeter when sent to the server right?

I guess, you just need to parse the string on the server!


thanks for the reply

the key value pair is not serialized into a string. it is a javascript object [like myObj[id] = 1; myObj[name] = 'test'....]

and i'm using Ajax to make a call to C# method [which does some sql] and

i need to pass the javascript object [myObj] to C# method and parse the object and use the values in sql

can you please give me some simple sample code for this

thank you

Sanjay


Hi sanjayk,

It is possible. Here is a sample shows how to pass a javascript object to a C# method through a button click event. For using Ajax call , you should do very little change.

ASPX:

<%@. Page Language="C#" AutoEventWireup="true" CodeFile="JSON.aspx.cs" Inherits="ClientScript_JSON" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title>JSON Test</title></head><body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <div> Display client serialize result:<asp:TextBox ID="TextBox1" runat="server" Text="5555" Style=""></asp:TextBox><br /> <br /> <asp:Label ID="Label1" runat="server" Text="Show FirstName here"></asp:Label> <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" /> </div> </form> <script type="text/javascript" language="javascript"> function pageLoad(){ var myObj = new Object(); myObj.FirstName = "Jonathan"; myObj.LastName = "Shen"; myObj.Title ="MSTF"; var serialiedObj = Sys.Serialization.JavaScriptSerializer.serialize(myObj); $get("<%=TextBox1.ClientID%>").value = serialiedObj; } </script></body></html>

C# Code:

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Web.Script.Serialization;

public partial class ClientScript_JSON : System.Web.UI.Page
{
JavaScriptSerializer serializer;

protected void Page_Load(object sender, EventArgs e)
{
serializer = new JavaScriptSerializer();
}
protected void Button1_Click(object sender, EventArgs e)
{
string jsonstring = Page.Request.Params["TextBox1"].ToString();
Dictionary<string, string> temp = serializer.Deserialize<Dictionary<string,string>>(jsonstring);
this.Label1.Text ="FirstName: "+temp["FirstName"].ToString();
}
}

For more details , please visit this url: http://ajax.asp.net/docs/ViewSample.aspx?sref=System.Web.Script.Serialization/cs/App_Code/ListItemCollectionConverter.cs

Hope it helps. If i misunderstood you, please let me know.


Hi Jonathan,

Thank you for your reply, i figured it out by passing Complex DataTypes to C# methods.

Sanjay

question on ajax & webservices

hello all again

here is what i'm doing,

i've a javascript object, which has key value pairs, and some values are objects themselves.

i'm passing this object to a method in a web service, and i'm able to get the values and also able to see the object (which is a value for some keys),

and also i can read that object (and values) in the callback function in my javascript file.

now my question is - i'm unable to refer to the object's value in .asmx file?

.js object looks like this:

myObj = new customObject(); // customObject is a public class in .cs file with get() and set() methods

myObj['id'] = 1;

myObj['name'] = 'test';

addressObj = new secondCustomObject(); // secondCustomObject is a public class in .cs file with get() and set() methods

addressObj['streeName'] = 'test Street Name';

addressObj['City'] = 'test City';

myObj['address'] = addressObj;

webservice.methodName(myObj, callback);

can anyone guide me how to read the addressObj's values in .asmx file?

Thank you

Sanjay

Hi

Would you please post a demo of your issue?

To troubleshoot this issue, we really need the source code of your webservice to reproduce the problem, so that we can investigate the issue in house. It is not necessary that you send out the complete source of your project. We just need a simplest sample to reproduce the problem. You can remove any confidential information or business logic from it.

Thank you.


Hi

Basically we only need to modify the proxy class that is generated when you add a web reference. I googled and found a nice article about this.

http://ryanfarley.com/blog/archive/2004/05/26/737.aspx


Let me know if you need more info.

Hope this helps.

Thanks!

NOTE:This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.


Hi

Demo:

Page:

<%@. Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

</script>

<script type="text/javascript">
function HelloWorld()
{
myObj = new person("Andrew","Yin");
myObj["firstName"] = "Jin Yu";
myObj["lastName"] = "Yin";
TestWebService.HelloWorld(myObj,SucceededCallback);
}

function person(fName, lName)
{
this.firstName = fName;
this.lastName = lName;
}
function SucceededCallback(result, eventArgs)
{
// Page element to display feedback.
var RsltElem = document.getElementById("ResultId");
RsltElem.value = result;
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager runat="server" ID="scriptManagerId">
<Services>
<asp:ServiceReference Path="TestWebService.asmx" />
</Services>

</asp:ScriptManager>
<input id="ResultId" type="text" />
<input id="Button1" type="button" value="button" onclick="javascript: HelloWorld();" /></div>
</form>
</body>
</html>

WebService And Class:

using System;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Web.Script.Services;


/// <summary>
/// Summary description for TestWebService
/// </summary>
[ScriptService]
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class TestWebService : System.Web.Services.WebService {

public TestWebService () {

//Uncomment the following line if using designed components
//InitializeComponent();
}

[WebMethod]
public string HelloWorld(person p) {
return "Hello World, " + p.firstName + " " + p.lastName;
}

}

public class person
{
public string firstName = "";
public string lastName = "";
}

Hope this helps.

Thanks


Thank you Yin-Yu for your reply,

I figured that part out, what i'm doing is pass the javascript object with key value pairs and some values are objects [with key value pairs] themselves.

in .asmx file i created custom datatypes for 1. key value pairs and 2. objects. this way i can see my elements [belongs to child objects] in my .asmx file

Thank you

Sanjay