如何在asp.net中限制整个页面上的回发 [英] how to restrict postback on entire page in asp.net

查看:66
本文介绍了如何在asp.net中限制整个页面上的回发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何限制asp.net中整个页面的回发
AND
如何通过asp.net中的JavaScript获取组合框中所选项目的Datamember和ValueMembet值

解决方案

猜猜是什么,我用ggogle找到了两个答案...


Ramesh Reddy11111写道:

如何
限制在asp.ne


中的整个页面上的回发
从控件中删除runat="server"属性

您还可以将onclick属性添加到控件并返回true,即

YourButton.Attributes.Add("onclick", "<script>return true</script>");




Ramesh Reddy11111写道:

如何通过JavaScript在组合框中获取所选项目的Datamember和ValueMembet值

<asp:TextBox ID="txtDate" runat="server"></asp:TextBox>
<img src="images\cal.gif" 
onclick="openCalendar(<% = txtDate.ClientID %>, 150, -150);return false;" />



更合适的方法是:

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="images/cal.gif" />



受保护的void Page_Load(对象发送者,EventArgs e)
{
ImageButton1.OnClientClick ="openCalendar(" + TextBox1.ClientID +," + X.ToString()+," + Y.ToString()+);返回false;";
}


要在组合框中获取值,您应该在页面加载事件中使用以下代码.........

if(!IsPostback)
{
//在此处写入在页面加载时执行的代码
}


how to restrict postback on entire page in asp.net
AND
how to get Datamember and ValueMembet value of selected item in combobox through JavaScript in asp.net

解决方案

Guess what, I found both answers with ggogle...


Ramesh Reddy11111 wrote:

how
to restrict postback on entire page in asp.ne



Remove the runat="server" attribute from the control

You can also add an onclick attribute to the control and return true i.e.

YourButton.Attributes.Add("onclick", "<script>return true</script>");




Ramesh Reddy11111 wrote:

how to get Datamember and ValueMembet value of selected item in combobox through JavaScript



<asp:TextBox ID="txtDate" runat="server"></asp:TextBox>
<img src="images\cal.gif" 
onclick="openCalendar(<% = txtDate.ClientID %>, 150, -150);return false;" />



A little more proper way would be:

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="images/cal.gif" />



protected void Page_Load(object sender, EventArgs e)
{
ImageButton1.OnClientClick = "openCalendar(" + TextBox1.ClientID + ", " + X.ToString() + ", " + Y.ToString() + ");return false;";
}


to get the value in the combobox you should use the following code in the page load event.........

if(!IsPostback)
{
//write here code that execute on page load
}


这篇关于如何在asp.net中限制整个页面上的回发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆