asp.net – 我可以通过div onclick事件调用函数后面的代码吗?
发布时间:2020-05-25 08:01:11 所属栏目:asp.Net 来源:互联网
导读:我的页面上有一堆div,它们是在运行时动态添加的. 当点击任何动态添加的div时 – 所有需要在后面的代码中调用相同的函数.每个div必须将自己的ID传递给函数. 我无法使用Web方法,因为函数需要识别单击哪个div,然后显示/隐藏/填充页面上的其他控件. 干杯伙计们 标
|
我的页面上有一堆div,它们是在运行时动态添加的.
干杯伙计们 标题控件和东西都在这里 <div id="div_Footer" class="HoverEdit" title="Click To Edit" runat="server" onclick="EditDiv(div_Footer)">
Footer Controls and stuff go here
</div>
然后在后面的代码中: Sub EditDiv(ID_ofDiv As String)
'Do some stuff to the controls on the page
'Swapping tabs,showing /hiding controls etc.
End Sub
解决方法我不习惯编写VB代码,所以我的例子是在C#中,但也许它可以帮助你开始.它可能不是实现这个的最干净的方法,但我会试一试: HTML <div id="div_Footer" class="HoverEdit" title="Click To Edit" runat="server" onclick="EditDiv(this)">
Footer Controls and stuff go here
</div>
客户 <script type="text/javascript">
function EditDiv(s,e){
var id = $(s).attr("id");
__doPostBack(id,id);
}
</script>
服务器 private void Page_Load(object sender,EventArgs e)
{
var arg = Request.Form["__EVENTTARGET"]; 'this will be empty on your first page request,but if the user click a div it will cause a postback to server,so this event will be fired again and will contain the div ID.
if(arg != null)
{
string divID = (string)arg;
'call your method with the argument.
}
}
有关这方面的更多信息,请访问: http://wiki.asp.net/page.aspx/1082/dopostback-function/ (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-core – 当返回null而不是控制器中设置的值时,Mode
- asp.net-core – asp.net核心身份中的多个SubDomain的cooki
- asp.net-core – 在ASP.NET Core中使用Entity Framework 6
- asp.net – IIS Web Garden中的Singleton对象
- asp.net-mvc – 用户不在角色时的ASP.NET登录重定向循环
- asp.net-mvc – 如何将URL参数绑定到具有不同名称的模型属性
- asp.net-mvc – 如何在ASP.NET MVC部分视图中使用匿名列表作
- asp.net-core-mvc – 将复杂对象存储在MVC 6中的TempData中
- 如何在Asp.Net Web API 2中使用Owin OAuth2修改令牌端点响应
- asp.net-mvc – Razor如何创建一个CheckBox并使其为READONL
推荐文章
站长推荐
- asp.net-mvc-3 – 找不到布局页面“{path}”
- asp.net-mvc – ASP.NET MVC报告
- ASP.NET Dropdownlist selectedindexchanged事件
- MVC/ASP.NET设计模板
- asp.net-mvc – 在Ubuntu 16.04中运行ASPNET Cor
- asp.net – Page.IsValid如何工作?
- asp.net – Server.Transfer throws执行子请求时
- asp.net-mvc – 仅当不使用角色时,如何重定向[Au
- asp.net-mvc – AllowAnonymous不能使用自定义Au
- asp.net-mvc-3 – 在查询字符串中使用“popup =
热点阅读
