在Javascript按钮上填写Hiddenfield从C#服务器端代码中单击? [英] Filling a Hiddenfield on javascript button click from C# serverside code?

查看:43
本文介绍了在Javascript按钮上填写Hiddenfield从C#服务器端代码中单击?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿伙计们,我很难找到一个好的指南,并且认为我可能会查找错误的关键字。



一位朋友提到Ajax可能这是完美的,但我还没有使用它,所以可以做一些关于下一步该做什么的建议。



我基本上想点击一个html按钮然后使用JavaScript将该按钮服务器端的ID发送到Select语句,select语句将填充隐藏字段,如果成功填充,客户端将使用该隐藏字段显示信息列表



我有这样的多个按钮,所以必须可以反复做而不刷新页面。 select语句where子句取决于单击的按钮。



服务器端代码是C#



可以我得到一些帮助或建议吗?如果我不够清楚,请告诉我,并试着重新提出我的问题,提前谢谢。

Hey guys, I''m struggling with finding a good guide for this and figured I might be looking up the wrong keywords.

A friend mentioned Ajax might be perfect for this but I haven''t used it so could do with some advise on what to do next.

I basically want to click a html button in then using JavaScript send the ID of that button server side to a Select statement, the select statement would fill a Hidden field and if populated successfully the client side would use that hidden field to display a list of information

I have multiple buttons like this so it has to be possible to do over and over without refreshing the page. The select statement where clause depends on the button clicked.

The server side code is C#

Can I get some help or advise on this? If I wasn''t clear enough please tell me and ill try to reword my questions, Thanks in advance.

推荐答案

这是一篇很好的短篇文章如何执行此操作的方法:使用jQuery直接调用ASP。 NET AJAX页面方法 [ ^ ]。



试一试,让我知道它是如何运作的!
Here is a nice and short article article on one of the ways on how you can do this: Using jQuery to directly call ASP.NET AJAX page methods[^].

Try this out and let me know how it works for you!






我建议你采取以下步骤。



- >添加ASP.NET按钮而不是HTML按钮,因为HTML按钮中没有回发功能。

- >将自定义属性tag添加到该按钮。

Hi,

I suggest the following steps to you.

-> Add ASP.NET button instead of HTML button, since there is no post back facility in HTML button.
-> Add custom attribute "tag" to that button.
<asp:Button ID ="ID1" runat="server" tag="test" ..



根据您想要区分按钮的内容,标签的值是您的愿望。



- >在服务器端事件中,根据按钮处理当前正在执行的事件。

- >即使有很多按钮,您也只能处理单一事件功能。

- >在事件函数中根据标签值识别按钮。


the value for tag is your wish, based on what you want to differentiate the buttons.

-> In server side event, handle the event as you are doing currently based on the button.
-> Even if many buttons, you handle in single event function only.
-> in the event function identify the button, based on the tag value.

string tag = ((Button)sender).Attributes["tag"].ToString();



- >执行select语句并在屏幕上显示详细信息。



希望它有所帮助。


-> execute the select statement and display the details in the screen.

hope it helps.


这篇关于在Javascript按钮上填写Hiddenfield从C#服务器端代码中单击?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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