Wednesday, March 28, 2012

change the visable of page controls

in my UserControl,there are 3 controls, DropDownList1,DropDownList2,TextBox1

DropDownList1,DropDownList2 are for the ajaxToolkit:CascadingDropDown

TextBox1.Visible=false;

but now when DropDownList1.SelectedItem.Text=="other",I want to change DropDownList2.Visible=false;TextBox1.Visible=true;

I make it via AJAX

<asp:ScriptManager ID="ScriptManager1" runat="server">
<Services>
<asp:ServiceReference Path="TypeService.asmx" />
</Services>
<Scripts>
<asp:ScriptReference Assembly="Microsoft.Web.Preview" Name="PreviewScript.js" />
</Scripts>
</asp:ScriptManager>

<script language="javascript">

...

Type_service.CheckOther(DropDownList1.value);

....

</script>

but the problem is now

how my TypeService.cs call the function in the CascadingDropDown.ascx.cs

Hi,shootarrow

I'm afraid that you cann't do this in that way.

You can do this at the client side!

Try this:

Default.aspx:

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

<!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>Untitled Page</title>

<script type="text/javascript">
// This function calls the Web Service method.
function EchoUserInput()
{
//Do something you want to do, e.g.delay the script execution
var echoElem = document.getElementById("EnteredValue");
WebService.HelloWorld(echoElem.value,SucceededCallback);
}
// This is the callback function that processes the Web Service return value.
function SucceededCallback(result)
{
var RsltElem = document.getElementById("Results");
RsltElem.innerHTML = result;
// Change the delay of the script execution back.
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Services>
<asp:ServiceReference Path="WebService.asmx" />
</Services>
</asp:ScriptManager>
<div>
<h2>
Simple Web Service</h2>
<p>
Calling a simple service that echoes the user's input and returns the current server
time.</p>
<input id="EnteredValue" type="text" />
<input id="EchoButton" type="button" value="Echo" onclick="EchoUserInput()" />
</div>
</form>
<hr />
<div>
<span id="Results"></span>
</div>
</body>
</html>

WebService.asmx:

<%@. WebService Language="C#" Class="WebService" %>

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

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ScriptService]
public class WebService : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld(String input)
{
System.Threading.Thread.Sleep(3000);
string inputString = Server.HtmlEncode(input);
if (!String.IsNullOrEmpty(inputString))
{
return String.Format("You entered {0}. The current time is {1}.", inputString, DateTime.Now);
}
else
{
return "The input string was null or empty.";
}
}
}

Hope this helps.

Let me know if you need more info.
You can also see this thread for more help:http://forums.asp.net/t/1115018.aspx

No comments:

Post a Comment