programmaticaly调用按钮onclick方法InvokeOnClick no [英] programmaticaly invoke the button onclick method InvokeOnClick no

查看:91
本文介绍了programmaticaly调用按钮onclick方法InvokeOnClick no的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表单,已经注册了javascript,因此弹出一个模式。

按钮单击将关闭表单。

现在我需要使用模态表单数据进行更新在它关闭之前。

我可以放第二个按钮并注册第二个

按钮的onclick属性

到javascript关闭表单用户点击上传按钮后

点击上传对数据库进行更新,然后以编程方式点击

第二个按钮,使用onclick属性查看已注册的

javascript并关闭模态

如果我以编程方式调用按钮onclick方法

找到另一个说使用的线程

this.InvokeOnClick(button1 ,EventArgs.Empty);

但是我的表格没有编译说没有定义

InvokeOnClick。?????

- -

cindy

I have a form, has javascript registered so a modal pops up.
Button click will close form.
Now I need to do an update with modal form data before it closes.
I can put a second button and register the onclick attribute of the second
button
to the javascript to close the form after user clicks upload button
click upload do the update to database then programmatically click the
second button the use on onclick attribute that sees the registered
javascript and closes the modal
HOw do I programmatically invoke the button onclick method
found another thread that say use
this.InvokeOnClick(button1, EventArgs.Empty);
but my form does not compile says there is not definition for
InvokeOnClick.?????
--
cindy

推荐答案

嗨Cindy,


感谢您发帖。


根据您的描述,您提到的问题是在ASP.NET Web

应用程序中。包含该按钮的页面将使用一些

客户端脚本来调用按钮的点击操作,对吗?


根据我的理解,对于客户端脚本,我们可以使用

" document.getElementById(buttonid).click();"调用某个按钮

元素'的点击事件。至于服务器端代码,由于按钮的'/ b $ b点击事件处理程序只是一个普通函数,你可以在你的

某个函数中调用它。到目前为止我还不太确定


"发现另一个线程说使用this.InvokeOnClick(button1,

EventArgs.Empty) ;


你提到过,它是否也特定于ASP.NET应用程序或winform?


如果有,请随时在此发布我没有得到任何东西。


问候,


Steven Cheng

Microsoft在线社区支持

=========================================== =======


在回复帖子时,请回复群组通过您的新闻阅读器

,其他人可以从您的问题中学习并从中受益。


================ ==================================

此帖子提供按现状 ;没有保证,也没有赋予任何权利。


安全! www.microsoft.com/security

(此帖子按原样提供,不作任何保证,并且不授予

权利。)

Hi Cindy,

Thank you for posting.

From your description, the problem you mentioned is within an ASP.NET web
application. And the page that contains the button will use some
client-side script to invoke the button''s click operation, correct?

Based on my understanding , for client-side script, we can use
"document.getElementById(buttonid).click();" to invoke the certain button
element''s click event. And as for server-side code, since the button''s
click event handler is just a normal function, you can just call it in your
certain function. What I''m not quite sure so far is the

"found another thread that say use this.InvokeOnClick(button1,
EventArgs.Empty); "

you mentioned, is it also specific to ASP.NET application or winform?

Please feel free to post here if there is anything I didn''t quite get.

Regards,

Steven Cheng
Microsoft Online Community Support
==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


公共类frmAuthor:系统.Web.UI.Page

{

//带有数据输入字段的父表单有上传按钮,

//用户点击上传按钮第一个客户端脚本打开模态窗口

//模态窗口中的用户操作导致模式窗口关闭

//执行返回到CmdUpload按钮onclick事件中的parent。 br />
//这边很好

protected void AddClientScript()

{

const string scriptName =" CALL_POPUP" ;;

StringBuilder sb = new StringBuilder("");

sb.Append(" \\\
< script language = \" javascript \\ \\">");

sb.Append(" \ nfunction getData(checkBoxL) istId)");

sb.Append(" \\\
{");

sb.Append(" \ nvar mystr = window.showModalDialog (''PopFrame.aspx'');");

sb.Append(" \ n}");

sb.Append(" \ n< / script>");

if(!IsClientScriptBlockRegistered(scriptName))

RegisterClientScriptBlock(scriptName,sb.ToString());

}

private void Page_Load(object sender,System.EventArgs e)

{

AddClientScript();

CmdUpload.Attributes [" onClick"] =" getData(''checkBoxListTest'')" ;;

}

private void InitializeComponent()

{

this.CmdUpload.C​​lick + = new System.EventHandler(this.CmdUpload_Click);

}


private void CmdUpload_Click(object sender,EventArgs e)

{

try {

//上传表单数据的代码

}

}


}


m odal window

公共类frmAttach:System.Web.UI.Page

{//模态窗口在iframe中打开

//表单已有字段和2个按钮,一个是CmdUpload,其中处理数据

//处理后我想以编程方式调用cmdClose的点击

//调用关闭的javascript窗口。

//手动点击按钮有效我想自动执行此操作。

private void Page_Load(object sender,System.EventArgs e)

{AddClientScript(); } $ / $
private void InitializeComponent()

{CmdUpload.C​​lick + = new System.EventHandler(this.CmdUpload_Click);}

protected void AddClientScript ()

{

string scriptName =" FIND_SELECTED_ITEM" ;;

StringBuilder sb = new StringBuilder("");

sb.Append(" \\\
< script language = \" javascript\">");

sb.Append(" \ nnfunction) Item_Selected()");

sb.Append(" \\\
{");

sb.Append(" \ nwindow.close() ;");

sb.Append(" \ n}");

sb.Append(" \ n< / script>" );

if(!IsClientScriptBlockRegistered(scriptName))

RegisterClientScriptBlock(scriptName,sb.ToString());

CmdClose.Attributes [" ; OnClick"] =" Item_Selected(); return false;" ;;

}

private void CmdUpload_Click(object sender,EventArgs e)

{

//上传表单数据的代码


//在这个论坛中有一个程序上的线程

//调用onclick方法并且他们说使用下面的代码

//但它不能为我编译我没有为InvokeOnClick定义

//这不是紧凑的应用程序

this.InvokeOnClick(this.CmdClose,EventArgs.Empty);

}

}

}

-

cindy

Steven Cheng [MSFT]"写道:
public class frmAuthor : System.Web.UI.Page
{
//parent form with field for data entry has upload button,
//user clicks upload button first client script opens modal window
//user action in modal window causes the close of the modal window
//execution returns to parent in the CmdUpload button onclick event.
//this side is all good
protected void AddClientScript()
{
const string scriptName = "CALL_POPUP";
StringBuilder sb = new StringBuilder("");
sb.Append("\n<script language =\"javascript\">");
sb.Append("\nfunction getData(checkBoxListId)");
sb.Append("\n{");
sb.Append("\nvar mystr = window.showModalDialog(''PopFrame.aspx'');");
sb.Append("\n}");
sb.Append("\n</script>");
if(!IsClientScriptBlockRegistered(scriptName))
RegisterClientScriptBlock(scriptName,sb.ToString() );
}
private void Page_Load(object sender, System.EventArgs e)
{
AddClientScript();
CmdUpload.Attributes["onClick"] = "getData(''checkBoxListTest'')";
}
private void InitializeComponent()
{
this.CmdUpload.Click += new System.EventHandler(this.CmdUpload_Click);
}

private void CmdUpload_Click(object sender, EventArgs e)
{
try {
//code to upload form data
}
}

}

the modal window
public class frmAttach : System.Web.UI.Page
{ //modal window is opened in iframe
//form has fields and 2 buttons, one is CmdUpload where data is processed
//after processing I want to programmatically invoke click of the cmdClose
//to call the javascript which closes the window.
//manually clicking the button works I want to automate this.
private void Page_Load(object sender, System.EventArgs e)
{ AddClientScript(); }
private void InitializeComponent()
{ CmdUpload.Click += new System.EventHandler(this.CmdUpload_Click);}
protected void AddClientScript()
{
string scriptName = "FIND_SELECTED_ITEM";
StringBuilder sb = new StringBuilder("");
sb.Append("\n<script language=\"javascript\">");
sb.Append("\nfunction Item_Selected()");
sb.Append("\n{");
sb.Append("\nwindow.close();");
sb.Append("\n}");
sb.Append("\n</script>");
if(!IsClientScriptBlockRegistered(scriptName))
RegisterClientScriptBlock(scriptName,sb.ToString() );
CmdClose.Attributes["OnClick"] = "Item_Selected();return false;";
}
private void CmdUpload_Click(object sender, EventArgs e)
{
//code to upload form data

//in this forum there is a thread on programmatically
//invoking the onclick method and they say to use code below
//but it does not compile for me I get no definition for InvokeOnClick
//this is not compact application
this.InvokeOnClick(this.CmdClose, EventArgs.Empty);
}
}
}
--
cindy
"Steven Cheng[MSFT]" wrote:
嗨Cindy,

感谢您发帖。

从您的描述中,您提到的问题是在ASP中.NET web
应用程序。包含该按钮的页面将使用一些
客户端脚本来调用按钮的点击操作,对吗?

根据我的理解,对于客户端脚本,我们可以使用
" document.getElementById(buttonid).click();"调用某个按钮
元素的点击事件。至于服务器端代码,由于按钮'的点击事件处理程序只是一个普通的功能,你可以在你的某个功能中调用它。到目前为止我不太确定的是

发现另一个线程说使用this.InvokeOnClick(button1,
EventArgs.Empty);

你提到过,它是否也特定于ASP.NET应用程序或winform?

如果有任何我没有得到的东西,请随时在这里发帖。

问候,

Steven Cheng
微软在线社区支持

============= =====================================

回复帖子时,请回复群组通过您的新闻阅读器,以便其他人可以从您的问题中学习并从中受益。

======================== ==========================

此帖子按原样提供。没有保证,也没有权利。

安全! www.microsoft.com/security
(此帖已提供按原样,没有保证,也没有赋予
权利。)
Hi Cindy,

Thank you for posting.

From your description, the problem you mentioned is within an ASP.NET web
application. And the page that contains the button will use some
client-side script to invoke the button''s click operation, correct?

Based on my understanding , for client-side script, we can use
"document.getElementById(buttonid).click();" to invoke the certain button
element''s click event. And as for server-side code, since the button''s
click event handler is just a normal function, you can just call it in your
certain function. What I''m not quite sure so far is the

"found another thread that say use this.InvokeOnClick(button1,
EventArgs.Empty); "

you mentioned, is it also specific to ASP.NET application or winform?

Please feel free to post here if there is anything I didn''t quite get.

Regards,

Steven Cheng
Microsoft Online Community Support
==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)



感谢您的回复Cindy,


嗯,我想我已经得到了你的appliation的代码逻辑。你想让

对话框网页的服务器端代码在开启者页面中调用一个方法

服务器端代码,是吗?如果是这种情况,我担心这不能完成,因为ASP.NET页面在服务器端没有其他页面感,

每个page的服务器端生命周期基于客户端对
服务器的请求。所以我们不能调用make一个页面来调用另一个页面中的server-sdie函数。


另外,InvokeOnClick也是如此。方法是winform的受保护方法

控制类而不是ASP.NET控件,所以这种方法显然是不正确的。


根据我的经验,如果你想让两个页面在服务器端进行一些

通信,你可以考虑让一个页面存储一些数据

或info在SessionState中,然后另一个页面可以访问该会话

状态以获取更新的值。


问候,


Steven Cheng

微软在线社区支持

========================= =========================

在回复帖子时,请回复群组通过您的新闻阅读器

,其他人可以从您的问题中学习并从中受益。


================ ==================================

此帖子提供按现状 ;没有保证,也没有赋予任何权利。


安全! www.microsoft.com/security

(此帖子按原样提供,不作任何保证,并且不授予

权利。)


Thank your for the response Cindy,

Well, I think I''ve got your appliation''s code logic. You want to let the
dialog web page''s server-side code to call a method in the opener page''s
server-side code, yes? If this is the case, I''m afraid this could not be
done because the ASP.NET pages have no sense of other pages at server-side,
each page''s server-side lifecycle is based on a request from client to
server. So we can not call make one page to call server-sdie function in
another page.

Also, the "InvokeOnClick" method is a protected method of the winform
Control class rather than ASP.NET control, so this approach is apparently
incorrect.

Based on my experience, if you want to make the two pages do some
communication at server-side, you may consider let one page store some data
or info in the SessionState and then the other page can access that session
state to get the updated value.

Regards,

Steven Cheng
Microsoft Online Community Support
==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)



这篇关于programmaticaly调用按钮onclick方法InvokeOnClick no的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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