如何引發一個button的事件在ASP.NET的Codebehind代碼中 在C/C++中,這個太好辦了.通給窗口發送消息就可.但是在...請高人指教.先謝了! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 使用 onserverclick;页面:<input type=button runat=server onserverclick="yourhanlder()" value="button1">cs:protected void yourhanlder(object sender ,System.EventArg e) {...} 不知道你“引發一個button的事件”是指客户端的还是服务器端的,客户端用RegisterStartupScript,引发服务器端事件只要直接调用事件方法就可以了,参数自己构造,可以为this和null,如果你只是想要刷新,用__doPostback('', '') 你們誤會我的意思了....我是想Raise一個事件. 還是看代碼吧!private void InitializeComponent(){ this.Button1.Click += new System.EventHandler(this.Button1_Click);}private void FireMyButtonEvent(){ this.Button1.OnClick(); // <-- ? }private void Button1_Click(object sender, EventArgs e){ txtCode.Text = "just demo";}就是想類似FireMyButtonEvent內的功能,只可惜Button沒有提供這方法! 楼上想在哪Raise就在哪调用this.Button1.OnClick(); private void FireMyButtonEvent(){ Button1_Click(this, null); } :(...lidong6(立冬) 沒有看清我的貼子; nZAI(学习的感觉真好): 我剛才都想說了但是還沒有貼上,我不需要這種方式(我當然知道),只需要像服務器那樣raise它. :( 我為什麼不需要那種方法啊!就是因為我的Button的Attributes["onclick"]內有一段javascript啊 不错,可以把事件代码写好,然后把AUTOPOSTBACK设置为FALSE,在需要产生时间的地方用JS调用__doPostBack事件 如果你要用javascript raise就這樣儸var aa=document.getElementById("Button1");aa.click();或者__doPostBack('Button1', null);寫在後臺註冊的javascript postBack更好Button btn=this.Page.FindControl("Button1");**.Attributes[**]=this.Page.GetPostBackHyperLink(btn, null);如果在後臺調用這個事件,直接把後臺代碼寫在你後臺想調用的地方不就行了。 enjoy330(*寒林*) 的方法不錯! 多謝了! 传递与接收参数问题 ASP.NET画曲线图,求示例或文档 字段状态标示的表示 小弟刚开始学习sql,感觉自己的语句效率太低,高手请给些思路,帮忙改改 一道关于数组的面试题!!! Ajax的问题(在线等) 帮帮小弟,很急的简单问题,谢谢! 请教大侠们关于DLL文件的生成方法? 生成桌面快捷方式的问题。 怎样才能使服务器端更改的数据主动发送的客户端的web上呢 用过eWebEditor的请进,看看这个问题~谢了 消除DataTable的重复数据?
使用 onserverclick;页面:<input type=button runat=server onserverclick="yourhanlder()" value="button1">cs:
protected void yourhanlder(object sender ,System.EventArg e) {...
}
我是想Raise一個事件. 還是看代碼吧!private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
}private void FireMyButtonEvent()
{
this.Button1.OnClick(); // <-- ?
}private void Button1_Click(object sender, EventArgs e)
{
txtCode.Text = "just demo";
}就是想類似FireMyButtonEvent內的功能,只可惜Button沒有提供這方法!
{
Button1_Click(this, null);
}
var aa=document.getElementById("Button1");
aa.click();
或者
__doPostBack('Button1', null);
寫在後臺註冊的javascript postBack更好
Button btn=this.Page.FindControl("Button1");
**.Attributes[**]=this.Page.GetPostBackHyperLink(btn, null);如果在後臺調用這個事件,直接把後臺代碼寫在你後臺想調用的地方不就行了。