专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > ASP.NET

post提交,后台接收到的值不能给服务器控件赋值?该怎么处理

发布时间:2011-06-22 17:14:42 文章来源:www.iduyao.cn 采编人员:星星草
post提交,后台接收到的值不能给服务器控件赋值?
C# code


Default.aspx:
            <div id="txt" runat="server"> </div>
            $.post("Default.aspx","id:100",function(){},"json");

Default.aspx.cs:
            protected void Page_Load(object sender, EventArgs e)
           {

                   txt.InnerHtml = "1";    //可以
       
                   if (Request.Form.Count == 1)
                  {
                       txt.InnerHtml = "2";  //不可以
                       Response.End();
                  }
           }

问题在post提交如何能让服务器控件txt成功赋值?求高手解答啊




------解决方案--------------------
Page_Load()里面,
一般要用到
if(!isPostBack){}
你先好好查查他的意义。
------解决方案--------------------
你如果不是用Ajax的话,把Response.End();这个方法去掉,终止该页的执行了,页面的内容不能输出当然看不到赋值后的内容。
------解决方案--------------------
探讨

$.post("Default.aspx","id:100",function(result){
$("#txt").html(result)
},"json");


protected void Page_Load(object sender, EventArgs e)
{

Response.Write("1")……

------解决方案--------------------
。。。。Response.Write 输出

赋值 在 function里用JS
------解决方案--------------------
正确的方法
<div id="txt"></div>
<script src="jquery-1.7.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
$.post('Default.aspx', { id: 100 }, function (data) {
$("#txt").html(data)
});
</script>



protected void Page_Load(object sender, EventArgs e)
{
if (Request.RequestType == "POST")
{
Response.ClearContent();
Response.Write(Request.Form["id"]);
Response.End();
}
}


------解决方案--------------------
这样好像是不行的哦
可以再post的回调函数中处理
 $.post("Default.aspx","id:100",function(result)
{
//这里处理
//...
},"json");
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: