日期:2014-05-17  浏览次数:20500 次

AJAX回调,pageload事件相关
问题是这样,我在页面上有DropDownList控件 选择一个选项,这时候他的selectindex肯定不为0
我有一个按钮,使用ajax回调本页面,在pageload中调用其他方法获取这个下拉列表的index. 一直是0;

是不是pageload还没走完,dropDownList的Index没有被自动赋回去? 

如果是这样,那么我要在pageload中处理这个事情怎么样可以获取到准确的selectIndex(DropDownList一定要用服务器控件)
------最佳解决方案--------------------
一会儿“回调”,一会儿“提交”,一会儿则是 Http Get,到底有没有谱呢?

在asp.net中,回调有其专门的概念,callback、postback都是。跟lz你的毫无关系。

而你的 Http Get,凭什么就能传送你的值1?

同时这Http Get怎么纠结到asp.net事件生命周期了呢?人家说的是postback,换句话说是asp.net ajax所执行的那种ajax能力,而不是不是你的所谓jquery ajax。
------其他解决方案--------------------

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!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>
    <script src="jquery-1.3.2-vsdoc.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function() {
            $("#DropDownList1").change(function() {
                var i = 0;
                var ddlVal = $(this).val();
                $("#DropDownList1 option").each(function() {

                    var oval = $(this).val();

                    if (oval == ddlVal) {
                        $("#Hidden1").val(i);
                        return;
                    }
                    i++;
                });
                form1.submit();

            })
        });    
    </script>
    
</head>
<body>
   <form id="form1" name="form1" method="get" runat="server">
   <input id="Hidden1" name="Hidden1" type="hidden" />
   <asp:DropDownList ID="DropDownList1" runat="server">
      <asp:ListItem>
      1
      </asp:ListItem>
 &nb