您的位置:程序门 -> .net技术 -> c#



dynamic populate控件件为什么无法返回onclick,该怎样实现?


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


dynamic populate控件件为什么无法返回onclick,该怎样实现?
发表于:2007-09-06 10:46:25 楼主
我用dynamicpopulateextender控件返回服务器查询结果,但是我返回时总提示我“web   service   call   failed:   500”。以下是代码一部分,其他的代码应该没问题,我都试成功了。
成功代码:
sreader[ "swdjb_basic_004 "].tostring()   +   " <br   /> ";
使用这个代码可以看到结果。
失败代码:
" <a   onclick=\ "alert( 'nihao ');\ "> "   +   sreader[ "swdjb_basic_004 "].tostring()   +   " </a> <br   /> ";
但是这行要是用response.write()往客户端写就一点问题,点击可以出来“nihao”。

谢谢!
发表于:2007-09-06 11:01:051楼 得分:0
怎么没人关注呀??
我把源码也贴上吧。
cs
using   system;
using   system.data;
using   system.configuration;
using   system.collections;
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.data.oledb;

public   partial   class   default2   :   system.web.ui.page
{
        protected   void   page_load(object   sender,   eventargs   e)
        {
        }
       
        [system.web.services.webmethodattribute(),   system.web.script.services.scriptmethodattribute()]
        public   static   string   getdynamiccontent(string   contextkey)
        {
                string   selresult;
                selresult   =   " ";
                string   datapath   =   httpcontext.current.server.mappath( "~/app_data/result.mdb ");
                string   strexsit   =   "select   count(*)   as   icount     from   dataset   where   swdjb_basic_004   like   '%% "   +   contextkey.tostring()   +   "%% ' ";
                string   streconnection   =   "provider=microsoft.jet.oledb.4.0;data   source= "   +   datapath;
                oledbconnection   econnection   =   new   oledbconnection(streconnection);
                oledbcommand   ecommand   =   new   oledbcommand(strexsit,   econnection);
                econnection.open();
                oledbdatareader   ereader   =   ecommand.EXECutereader();
                ereader.read();
                string   count   =   ereader[ "icount "].tostring();
                ereader.close();
                econnection.close();
                if   (count   ==   "0 ")
                {
                        selresult   =   " <font   style= 'color:   #ff0033; '> 未找到与您输入关键字相关的纪录! </font> ";
                }
                else
                {
                        selresult   =   " ";
                        string   strselect   =   "select   swdjb_basic_001,swdjb_basic_004   from   dataset   where   swdjb_basic_004   like   '%% "   +   contextkey.tostring()   +   "%% ' ";
                        string   strsconnection   =   "provider=microsoft.jet.oledb.4.0;data   source= "   +   datapath;
                        oledbconnection   sconnection   =   new   oledbconnection(strsconnection);
                        oledbcommand   scommand   =   new   oledbcommand(strselect,   sconnection);
                        sconnection.open();
                        oledbdatareader   sreader   =   scommand.EXECutereader();
                        sreader.read();
                        //有问题部分就在下面
                        while   (sreader.read())
                        {
                                string   midstr;
                                midstr   =   string.format( " <span   onclick=alert(\ 'nihao\ ');> {0} </span> <br   /> ",   sreader[ "swdjb_basic_004 "].tostring());
                                //midstr   =   " <a   onclick=\ "alert(\ 'nihao\ ');\ "> &nbsp; "   +   sreader[ "swdjb_basic_004 "].tostring()   +   " </a> "   +   " <br   /> ";
                                selresult   =   selresult   +   midstr;
                                //string   midstr;
                                //midstr   =   " <a   onclick=\ "alert( 'nihao ');\ "> "   +   sreader[ "swdjb_basic_004 "].tostring()   +   " </a> "   +   " <br   /> ";
                                //selresult   =   selresult   +   midstr;
                        }
                        sreader.close();
                        sconnection.close();
                }

                return   selresult;
        }
}
aspx
<%@   page   language= "c# "   autoeventwireup= "true "   codefile= "default.aspx.cs "   inherits= "default2 "   %>

<%@   register   assembly= "ajaxcontroltoolkit "   namespace= "ajaxcontroltoolkit "   tagprefix= "cc1 "   %>

<!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> 无标题页 </title>
        <link   href= "stylesheet.css "   rel= "stylesheet "   type= "text/css "   />
</head>
<body   style= "text-align:   center ">
        <form   id= "form1 "   runat= "server ">
                <div   style= "text-align:   center ">
                        <asp:scriptmanager   id= "scriptmanager1 "   runat= "server ">
                        </asp:scriptmanager>
                        <script   type= "text/javascript ">
                                function   pushinput()
                                {
                                        var   seachobj   =   document.getelementbyid( 'txtinput ')
                                        var   seachvalue   =   seachobj.value;
                                        if(   seachvalue   ==   " "   )
                                        {
                                                alert( "搜索关键字不能为空! ");
                                                return   false;
                                        }
                                        var   behavior=$find( 'dpe ');
                                        if(behavior)
                                        {
                                                behavior.populate(seachvalue);
                                        }
                                }
                        </script>
                        <input   id= "txtinput "   type= "text "   /> <br   />
                        <input   id= "btnok "   type= "button "   value= "确定 "   onclick= "pushinput(); "   />
                        <input   id= "btnres "   type= "reset "   value= "清空 "   />
                        <asp:panel   id= "showresult "   runat= "server "   height= "174px "   width= "240px "   cssclass= "dpenormal "   >
                        </asp:panel>
                        <cc1:dynamicpopulateextender   id= "dpe "   runat= "server "   servicemethod= "getdynamiccontent "     updatingcssclass= "dpeupdating "
                                targetcontrolid= "showresult "> </cc1:dynamicpopulateextender>
                </div>
        </form>
</body>
</html>
发表于:2007-10-18 17:26:312楼 得分:0
顶..我也遇到同样问题
web   service   call   failed:   12030


快速检索

最新资讯
热门点击