老是搞忘怎么写,简单的做一下备忘
public string m_Callback = "";
public string sCallBackFunctionInvocation = "";
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
Session["SourceLayer"] = "";
}
DropDownList1.Attributes.Add("onchange", "ChangeDDLContext()");
m_Callback = Page.ClientScript.GetCallbackEventReference(Page, "argument", "processCallbackResult", "context", "processCallbackError", true);
sCallBackFunctionInvocation = Page.ClientScript.GetCallbackEventReference(this, "message", "HandleResponse", "context", "postBackError", true);
}
protected void Page_PreRender(object sender, EventArgs e)
{
if (!IsPostBack)
{
ESRI.ArcGIS.ADF.Web.DataSources.IMapFunctionality mf = (ESRI.ArcGIS.ADF.Web.DataSources.IMapFunctionality)Map1.GetFunctionality(1);
ESRI.ArcGIS.ADF.Web.DataSources.IGISResource gisresource = mf.Resource;
bool supported = gisresource.SupportsFunctionality(typeof(ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality));
if (supported)
{
ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality qfunc=(ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality)gisresource.CreateFunctionality(typeof(ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality), null);
string[] libs;
string[] lnames;
qfunc.GetQueryableLayers(null, out libs, out lnames);
for (int i = 0; i < lnames.Length; i++)
{
DropDownList1.Items.Add(lnames[i]);
}
Session["SourceLayer"] = DropDownList1.Items[0].Value;
}
}
}
#region ICallbackEventHandler成员
private string _callbackArg;
string ICallbackEventHandler.GetCallbackResult()
{
return RaiseCallbackeEvent(_callbackArg);
}
void ICallbackEventHandler.RaiseCallbackEvent(string eventArgument)
{
_callbackArg = eventArgument;
}
#endregion
private string RaiseCallbackeEvent(String _callbackArg)
{
string v = "";
if (_callbackArg.Contains("ddl"))
{
ChangeDropDownListServer(_callbackArg);
}
else if (_callbackArg.Contains("Map"))
{
//try
//{
//请求字符串
NameValueCollection keyValColl = CallbackUtility.ParseStringIntoNameValueCollection(_callbackArg);
if (keyValColl["Type"].ToString() == "findPath")
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
//起点名称
string Input1 = keyValColl["p1"];
//终点名称
string Input2 = keyValColl["p2"];
//路径分析
//无障碍点分析类调用
//findpath findpath = new findpath();
//findpath.doFindPath(Input1, Input2, Map1);
////有障碍点分析类调用
//findBarrierPath findpath = new findBarrierPath();
//findpath.doFindPath(Input1, Input2, Map1);
//有多个障碍点分析类调用
findBarrierPath2 findpath = new findBarrierPath2();
findpath.doFindPath(Input1, Input2, Map1);
//直接调用
// doFindPath(Input1, Input2);
}
}
// innercontent相当于innerhtml
// CallbackResult cr = new CallbackResult("div", "griddiv", "innercontent", returnstring);
//CallbackResult crl = new CallbackResult("Gradview1", null, "innercontent", null);
//Map1.CallbackResults.Add(crl);
v = Map1.CallbackResults.ToString();
return v;
<script type="text/javascript" language="javascript">
var context;
function ChangeDDLContext()
{
context = 'DDLContext';
ChangeClient();
}
function ChangeClient()
{
var message;
if (context == 'DDLContext'){
var ddl1value = document.getElementById('DropDownList1').value;
message = 'ddl';
message += ',' + ddl1value;
}
if (context == 'BufferTextBox'){
var bufboxvalue = document.getElementById('TextBox1').value;
message = 'bufbox';
message += ',' + bufboxvalue;
}
<%=sCallBackFunctionInvocation%>
}
function search()
{
//起点的名称
var v1=document.getElementById("txtBegin").value;
//终点的名称
var v2=document.getElementById("txtEnd").value;
var argument = "ControlID=Map1&ControlType=Map&Type=findPath&p1="+v1+"&p2="+v2;
var context = "Map";
var rv=<%= m_Callback %>;
eval(rv);
}
function searchClosestFacility()
{
//设施的名称
var v1=document.getElementById("txtFacility1").value;
var v2=document.getElementById("txtFacility2").value;
//事件的名称
var v3=document.getElementById("txtIncident").value;
var argument="ControlID=Map1&ControlType=Map&Type=ClosestFacility&p1='"+v1+"'&p2='"+v2+"'&p3="+v3;
var context="Map";
var rv=<%=m_Callback %>;
eval(rv);
}
function processCallbackError()
{
alert(66);
}
function HandleResponse()
{
}
</script>
<script type="text/javascript" language="javascript">
var context;
function ChangeDDLContext()
{
context = 'DDLContext';
ChangeClient();
}
function ChangeClient()
{
var message;
if (context == 'DDLContext'){
var ddl1value = document.getElementById('DropDownList1').value;
message = 'ddl';
message += ',' + ddl1value;
}
if (context == 'BufferTextBox'){
var bufboxvalue = document.getElementById('TextBox1').value;
message = 'bufbox';
message += ',' + bufboxvalue;
}
<%=sCallBackFunctionInvocation%>
}
function search()
{
//起点的名称
var v1=document.getElementById("txtBegin").value;
//终点的名称
var v2=document.getElementById("txtEnd").value;
var argument = "ControlID=Map1&ControlType=Map&Type=findPath&p1="+v1+"&p2="+v2;
var context = "Map";
var rv=<%= m_Callback %>;
eval(rv);
}
function searchClosestFacility()
{
//设施的名称
var v1=document.getElementById("txtFacility1").value;
var v2=document.getElementById("txtFacility2").value;
//事件的名称
var v3=document.getElementById("txtIncident").value;
var argument="ControlID=Map1&ControlType=Map&Type=ClosestFacility&p1='"+v1+"'&p2='"+v2+"'&p3="+v3;
var context="Map";
var rv=<%=m_Callback %>;
eval(rv);
}
function processCallbackError()
{
alert(66);
}
function HandleResponse()
{
}
</script>