使用事件将信息从 javascript 传递到 C#
我有这个 ASP.net 组件:
<asp:Button ID="Button4" runat="server" Text="Submit Entry" CssClass="eventSubmitButton" OnClick="SubmitData"/>
并且我想向这个以 C# 实现的 SubmitData 方法发送一些附加信息。例如,我想在javascript中发送一个int集。我读到,执行此操作的方法是扩展 EventArgs 类。
不过,我实在不太明白。当然,我可以在 C# 中实现一个扩展 EventArgs 的类,但这如何帮助我从 Javascript 传递信息呢?
还有另一种方法可以在回发期间传递任意信息吗?
I have this ASP.net component:
<asp:Button ID="Button4" runat="server" Text="Submit Entry" CssClass="eventSubmitButton" OnClick="SubmitData"/>
and I'd like to send some additional information to this SubmitData method, implemented in C#. For example, I want to send an int set in the javascript. I've read that the way to do this is extending the EventArgs class.
However, I don't really understand. Sure I can implement a class that extends EventArgs in C#, but how does that help me pass information from my Javascript?
Is there another way to pass arbitrary information during postback?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只需将其分配给 JavaScript 中的隐藏字段并使用 Request.Form["FieldName"] 读取它
Simply assign it to a hidden field in javascript and read it using Request.Form["FieldName"]
按钮的 CommandArgument 属性用于传递 EventArgs,尽管它是服务器端属性并且无法通过 Javascript 访问。
我相信,最好的方法是使用隐藏字段并通过 JavaScript 设置值。这是示例代码...
CommandArgument property for button is used to pass EventArgs, though its a ServerSide property and cannot be accessed through Javascript.
I believe, best way would be to use a hiddenfield and set value through JavaScript. Here's the sample code...