<script>
function xxx()
{
           if(此处需要调用后台代码查询数据库进行效验)
             {
              }
            ......(操作客户端设备的代码)            此处需要调用后台代码更新数据库
          }
<script><IMG id="yy" onclick="xxx()" src="../Image/xx.gif">请问该怎么做?或者还有其他方案能达到如此效果(三者的执行顺序不能变,而且只点击一次)?
请高手指点。

解决方案 »

  1.   

    function xxx()
    {
               if(<% funtionName() %>)
                 {
                  }
                ......(操作客户端设备的代码)            此处需要调用后台代码更新数据库
              }
    <script><IMG id="yy" onclick="xxx()" src="../Image/xx.gif">cs code
    public bool funtionName()
    {
    bool success = false;
    {
    //put you code here 
    }
    return success;
    }
      

  2.   

    <%# 函数 %>
    这样也是可以的吧
      

  3.   

    有2个解决办法
    1:可以用隐藏按钮。
    2:可以__dopostback一下。
      

  4.   

    用Ajax方法调用:
    function()
    {
       var objHttp = new ActiveXObject("Msxml2.XMLHTTP");
       strHttp = "getFilesBase.aspx?state=" + fileName;
       objHttp.open("get", strHttp, false);
       objHttp.send();
    }
    getFilesBase.aspx,getFilesBase.cs代码:Page_Load函数可调用任意getFilesBase.cs函数:
    private void Page_Load(object sender, System.EventArgs e)
    {

    string strFilePath = @"F:\csv\";
        string strRequest = Request.Params[0];
    strFilePath += strRequest;
    System.IO.Stream iStream = null;

    //*
    // Buffer to read 10K bytes in chunk:
    byte[] buffer = new Byte[10000]; // Length of the file:
    int length; // Total bytes to read:
    long dataToRead; // Identify the file name.
    string  filename  = System.IO.Path.GetFileName(strFilePath); try
    {
    // Open the file.
    iStream = new System.IO.FileStream(strFilePath, System.IO.FileMode.Open,
    System.IO.FileAccess.Read,System.IO.FileShare.Read);               
    // Total bytes to read:

    dataToRead = iStream.Length;
                    Response.Charset = "Shift-JIS";
    Response.ContentType = "application/octet-stream";
    Response.AddHeader("Content-Disposition", "attachment; filename=" + filename); // Read the bytes.
    while (dataToRead > 0)
    {
    // Verify that the client is connected.
    if (Response.IsClientConnected)
    {
    // Read the data in buffer.
    length = iStream.Read(buffer, 0, 10000);
    //UnicodeEncoding temp = new UnicodeEncoding();
    //System.Text.UTF8Encoding temp = new UTF8Encoding();
                            System.Text.Encoding temp = System.Text.Encoding.Default;
    string strBuffer = temp.GetString(buffer);

    // Write the data to the current output stream.
    //Response.OutputStream.Write(buffer, 0, length);
    Response.Write(strBuffer); // Flush the data to the HTML output.
    Response.Flush(); buffer= new Byte[10000];
    dataToRead = dataToRead - length;
    }
    else
    {
    //prevent infinite loop if user disconnects
    dataToRead = -1;
    }
    }
      

  5.   

    使用Ajax 调用方法很多,你可以在网上查一下.
      

  6.   

    隐藏按钮可以的,我是经常用的,还有ajax我想应该也可以的,其他的没有试过
      

  7.   

    cw888() 使用Ajax的方法很好
      

  8.   

    搜索Ajax,
    实例
    http://www.microsoft.com/china/msdn/library/webservices/asp.net/ASPNetSpicedAjax.mspx