Showing posts with label method. Show all posts
Showing posts with label method. Show all posts

Wednesday, March 28, 2012

programatically disable dropdown in Ajax updatepanel

I've searched high and low for what seemed would be a simple and frequently used method to access the properties of a drop down contained in a Ajax UpdatePanel without finding anyone who seems to have needed to do this or who has solved it. Maybe Microsoft decided nobody would ever want to do such a weird thing!

I have users with various permission levels. Depending on their level, on page load I need to disable drop downs which are contained within Ajax Updatepanels.

I can expose the properties of the UpdatePanels themselves but they do not support the enable property, only invisible which is no help.

Anyone know how this is done ?

Thanks

Aren't you able to just set the Enabled property of the appropriate DropDownList's?


Dont depends only on UI elements enable/disable state. Also enusre the User level in server side. Can pls post some code i mean in which point you want to disable the dropdown list.

Use CascadingDropDown control in AJAXControlToolKit

http://www.asp.net/AJAX/AjaxControlToolkit/Samples/CascadingDropDown/CascadingDropDown.aspx


Hi,

Are you using the AJAX extension version 1.0.61025.0 ?

I'm using this one. The controls inside UpdatePanel can be accessed directly. For instance:

<%@. 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"> protected void Page_Load(object sender, EventArgs e) { DropDownList1.Enabled = false; }</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 ID="ScriptManager1" runat="server"> </asp:ScriptManager> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:DropDownList ID="DropDownList1" runat="server"> </asp:DropDownList> </ContentTemplate> </asp:UpdatePanel> </div> </form></body></html>

Monday, March 26, 2012

public CascadingDropDownNameValue[] GetAllDistrict(string knownCategoryValues, string cate

want to know whether i can pass more than two arguments in the above shown webservice method..i intend to implement it in a cascading drop down list.. having two sibling dropdown lists...

so i want to pass three arguments eg..cid, brid, deptid...but a webservice allows only two of the kind...

Hi,

You can pass more information via a third parameter contextKey. For instance:

public static AjaxControlToolkit.CascadingDropDownNameValue[]
GetDropDownContentsPageMethod(string knownCategoryValues, string category, string contextKey)

protected void Page_Load(object sender, EventArgs e)
{
CascadingDropDown2.ContextKey = "contextKeyOf2";
}

Hope this helps.

Saturday, March 24, 2012

Question about Overriding Methods

Greetings,
I'm having trouble seeing the base class method if I've overriden it...I am not sure what I'm doing wrong. I've tried to study how the Atlas framework is using it, but nothing is working. Here's my code:
Type.registerNamespace("Juicy.Collections");
Juicy.Collections.ArrayList = function() {
var _items = new Array();
this.get_item = function(i) { return _itemsIdea [I]; }
this.get_length = function() { return _items.length; }
this.add = function(item) { _items.add(item); }
this.clear = function() { _items.clear(); }
this.dispose = function() { for (var i = 0; i < _items.length; i++) { _itemsIdea [I].dispose(); _itemsIdea [I] = null; } _items.clear(); }
}
Type.registerClass("Juicy.Collections.ArrayList", null, Web.IDisposable);
Type.registerNamespace("Juicy.UI");
Juicy.UI.TabPageCollection = function(owner) {
Juicy.UI.TabPageCollection.initializeBase(this);
var _owner = owner;
this.add = function(tabPage) { Juicy.UI.TabPageCollection.callBaseMethod(this, "add", tabPage); } // The callBaseMethod always evaluates to null.
Juicy.UI.TabPageCollection.registerBaseMethod(this, "add"); }
Type.registerClass("Juicy.UI.TabPageCollection", Juicy.Collections.ArrayList);
// Code to test the above. The get_length() works fine, but the add does not increment properly.
var tabPages = new Juicy.UI.TabPageCollection();
tabPages.add("foo");
alert(tabPages.get_length());
I want the "add" method in TabPageCollection to do some work, and then call the inherited add. But the callBaseMethod does not resolve.
Any ideas anyone? This is driving me nuts here.
Thanks,
William

I think I found the answer to my question. The base class has to have a call to "registerBaseMethod" for the method that may be overridden.
Just as an idea, wouldn't it be more intuitive for the derived class to have syntax/method indicating that it is overriding the base? I can't off the top of my head think of how this could be done, but it took me awhile to figure out how the current manner works. Perhaps Type.overrideMethod(this, methodName, someFunctionReference).
Thanks,
William

You need to register the base method in the ArrayList class.

Juicy.Collections.ArrayList.registerBaseMethod(this, 'add');

Then your callBaseMethod should start resolving. However, you need to make one more small tweak - the arguments to the base method are passed as an array of arguments. So you would have:

Juicy.UI.TabPageCollection.callBaseMethod(this, 'add', [tabPage]);

Wednesday, March 21, 2012

Question for custom controls builder

Hi,

I build a common (non AJAX) custom control.

My control renderJavaScript with thePage.ClientScript.RegisterClientScriptResource method, so it do not work when inside an UpdatePanel.

How can we detect if the control is placed inside an UpdatePanel and use the correct method to render JavaScript ?

I found a very interesting article but it seems that it do not work with AJAX RTM bits :
http://weblogs.asp.net/leftslipper/archive/2006/11/13/HOWTO_3A00_-Write-controls-compatible-with-UpdatePanel-without-linking-to-the-ASP.NET-AJAX-DLL.aspx

How do you deal with that problem ?

The best way (I think) would be to have it happen at the server level by iterating over the control hierarchy (looking at its ancestor containers) until it gets to Page to see if any of them are of type UpdatePanel.

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

Questions about bindings, tables, listviews...

I have a web service with a method, for example, GetCities, returns an array of cities. I want to bind it to a grid-like structure, the first column being the city name and the second a delete button. Then I want to implement the delete button that deletes the city and refreshes the list. All that within an .ascx control - I want to be able to place multiple of these on the same page.

I struggled with this with Atlas - it doesn't seem like a listview is the right way to go for this and I am not sure how to get the delete button to invoke some method to delete a row.

Anyone has a working example of something like this end-to-end?

Thx
dB.

A listview is appropriate for that. Check out this post (which uses server controls, but that'll give you the general idea).http://forums.asp.net/1123018/ShowPost.aspx