我的页面十分简单,在一个页面Test.aspx上放一个UpdatePanel1,里面放了一个PlaceHolder1控件和一个Button1按钮,点击Button时动态加载一个UserControl(WebUserControl.ascx),UserControl里有一个LinkButton1和一个TextBox1,点击LinkButton1使得TextBox1的Text加上等于“ABC”。Test.aspx代码:
public partial class Test : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (ViewState["ControlID"] != null)
{
AddControl();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
ViewState["ControlID"] = "WebUserControl";
AddControl();
} private void AddControl()
{
UserControl uc = (UserControl)LoadControl("~/WebUserControl.ascx");
uc.ID = "WebUserControl";
this.PlaceHolder1.Controls.Clear();
this.PlaceHolder1.Controls.Add(uc);
}
}WebUserControl.ascx代码:
public partial class WebUserControl : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{ }
protected void LinkButton1_Click(object sender, EventArgs e)
{
this.TextBox1.Text += "ABC";
}
}前置页代码我就不贴了,很简单,控件托上去就有了。
我的UpdatePanel的设置都没问题,Atlas的版本也最新。我用Button代替LinkButton就没问题,但用LinkButton就会报Javascript的错误。不知哪位高手可以解决?小弟在这里多谢了!
public partial class Test : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (ViewState["ControlID"] != null)
{
AddControl();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
ViewState["ControlID"] = "WebUserControl";
AddControl();
} private void AddControl()
{
UserControl uc = (UserControl)LoadControl("~/WebUserControl.ascx");
uc.ID = "WebUserControl";
this.PlaceHolder1.Controls.Clear();
this.PlaceHolder1.Controls.Add(uc);
}
}WebUserControl.ascx代码:
public partial class WebUserControl : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{ }
protected void LinkButton1_Click(object sender, EventArgs e)
{
this.TextBox1.Text += "ABC";
}
}前置页代码我就不贴了,很简单,控件托上去就有了。
我的UpdatePanel的设置都没问题,Atlas的版本也最新。我用Button代替LinkButton就没问题,但用LinkButton就会报Javascript的错误。不知哪位高手可以解决?小弟在这里多谢了!
换成Panel也一样。应该不是这个问题。
启示我做这个例子是因为在GridView中SelectCommand是linkButton类型
正是因为碰到了才做这个例子尝试的,结果与我的预料完全相同。所以法帖求助帮忙!
谢谢!
我在test页面加了个linkbutton然后dispaly:none,这样就能用了。
大家揣摩一下到底啥道理啊
我在页面加了一个linkbutton之后,他会自动给页面添加<script type="text/javascript">
<!--
var theForm = document.forms['form1'];
if (!theForm) {
theForm = document.form1;
}
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}
}
// -->
</script>
这样就找到调用的方法了
linkbutton如果visible=false他也不会加这个方法
照你的说法试了一下,果然可以。多谢
不过我也不知道原因。请高手赐教!
<!--
var theForm = document.forms['form1'];
if (!theForm) {
theForm = document.form1;
}
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}
}
// -->
</script>
但这样用好像linkbutton的样式都没了
我现在在GridView中的点击CommondField的“选择”后,该行的样式就没了,不知道什么原因,请执教!
是这个问题嘛?