数据列表itemcommand不触发? [英] Datalist itemcommand is not firing?

查看:142
本文介绍了数据列表itemcommand不触发?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的项目中使用了一个带有项命令属性和itemdataboundproperty的数据列表.在项数据绑定中,我在imagebutton中调用了一个javascript?之后,我的itemcommand属性没有触发.

然后,我在数据列表中创建按钮,并在相同的javascript中调用按钮单击.现在,item命令属性正在触发,但未显示javascript modalpopup.

如果一个在工作,然后另一个不在工作.但是我必须需要两个功能才能工作.

我怎样才能做到这一点.请帮助任何一个人.

I am using one datalist in my project with item command property and itemdataboundproperty.In item data bound i call one javascript in imagebutton?? after do this my itemcommand property is not firing.

Then i create the button in datalist and call the button click in same javascript. Now item command property is firing but the javascript modalpopup is not displaying.

if one is working and then another one is not working. but i must need two functionalities to work.

How can i do this. help any one please

推荐答案

,您需要从所调用的javascript函数中返回真实值.如果javascript函数最后返回true,则该页面将被发布回服务器.

默认情况下,javascript函数将返回false,这就是为什么您的页面不回传数据的原因. 这是一个示例:
you need to return true value from javascript function you are invoking. The page will be post back to the server if javascript function returns true at the end.

By default javascript function will return false, that is why your page is not posting back the data.
here is an example:
<input type="submit"  önclick="return doSomething();" />

<script>
function doSomething()
{
 ''''do something...
return true;
}
</script>



希望这会有所帮助
谢谢,
hemant





Hope this will help
Thanks,
hemant



btntest.Attributes.Add("onclientclick", "javascript:ModalPopupsConfirm(''" + hdnmin.ClientID + "'',''" + Pdtdesc.ClientID + "'');return false;");


您的代码有2个问题:

1- onclientclick:
问题:OnClientClick 是asp.net按钮的服务器端属性,无法像这样添加,而Attributes 集合则保留为客户端呈现的属性,如下所示:它是.上一行将为客户端生成类似以下内容的内容:


There are 2 problems with your code:

1- onclientclick:
The Problem: OnClientClick is a asp.net button''s server side property it can''t be added like this, while Attributes collection keeps attributes to be rendered for client end as-it-is. The above line will generate something like below for client:

<input type="Submit"  önclientclick="javascript:ModalPopupsConfirm(''" + hdnmin.ClientID + "'',''" + Pdtdesc.ClientID + "'');return false;" />


上面的客户端代码中的onclientclick 应该是onClick

解决方案:您需要修改代码以添加onClick属性而不是onclientclick,如下所示:


The onclientclick in the above client code should be onClick

The Solution: you need to modify your code to add onClick attribute instead of onclientclick, like this:

btntest.Attributes.Add("onClick","...your javascript code....");




or

btntest.OnClientClick = "javascript:ModalPopupsConfirm(''" + hdnmin.ClientID + "'',''" + Pdtdesc.ClientID + "'');return false;"



上面的代码将确保您的Javascript得到执行,但不能保证会引发itemcommand 事件,因为您的JavaScript中存在一个问题,该问题不允许您的按钮将当前页面发布回服务器,即不进行回发.要解决它,请参阅问题和解决方案2.

2- Javascript:



The above code will make sure your Javascript gets executed but it wont guarantee that itemcommand event will be raised because there is a problem in your javascript that wont allow your button to post current page back to server i.e. no postback. To solve it see Problem and solution 2.

2- Javascript:

javascript:ModalPopupsConfirm(''" + hdnmin.ClientID + "'',''" + Pdtdesc.ClientID + "'');return false;


问题:上面的代码与下面的javascript函数相同:


The problem: The above code is identical to below javascript function:

function OnClickFunction()
{
     ModalPopupsConfirm(''" + hdnmin.ClientID + "'',''" + Pdtdesc.ClientID + "'');
     return false;
}



当您单击按钮时,将首先执行ModalPopupsConfirm 函数,然后执行return false 2条语句.因为最后您返回的是false,所以您要求浏览器不要提交页面,因为单击按钮时某些验证失败.

解决方案:
页面的逻辑要求:如果用户在弹出窗口中单击是",则将页面发回并引发itemcommand事件,但是如果用户对确认弹出窗口说否",则不执行任何操作并停留在页面上.
2.1-删除return false
2.2-从ModalPopupsConfirm函数返回适当的布尔值. (我不确定我是否可以使用ajax模态弹出窗口)



When you will click on the button, 2 statements will be executed first the ModalPopupsConfirm function and then return false. Because at the end you are returning false you are asking your browser to not submit your page because of some validation failure on button click.

The Solution:
The logic of your page demands: if user clicks yes in the pop-up post the page back and raise the itemcommand event but if user says no to the confirm pop-up don''t do anything and stays on the page.
2.1 - Remove return false
2.2 - Return proper bool from ModalPopupsConfirm function. (i''m not sure about this i dont'' work with ajax modal popup)

function ModalPopupsConfirm(hidden, Pdtdesc) {
            var ItemCount = gethdnvalue(hidden);
            var ProductName = document.getElementById(Pdtdesc).innerHTML;
            document.getElementById(hidden).value = ItemCount;
            return ModalPopups.Confirm("idConfirm1",
        "Confirm your Order",
        "<div style='padding: 25px; width:300px'>You Selected " + ItemCount + " Items For " + ProductName + "<br></br>Are you sure?</div>",
        {
            yesButtonText: "Yes",
            noButtonText: "No",
            onYes: "ModalPopupsConfirmYes()",
            onNo: "ModalPopupsConfirmNo()"

        }

    );


ModalPopups.Confirm..之前添加return.代码
2.3-在Attributes.Add或OnClientClick中的javascript函数调用之前添加return


add return before ModalPopups.Confirm... code
2.3 - add return before javascript function call in Attributes.Add or OnClientClick

btntest.Attributes.Add("onClick", "return ModalPopupsConfirm(''" + hdnmin.ClientID + "'',''" + Pdtdesc.ClientID + "'');");







or

btntest.OnClientClick = "return ModalPopupsConfirm(''" + hdnmin.ClientID + "'',''" + Pdtdesc.ClientID + "'');";



最终解决方案:
实施第2点的更改,即从2.1更改为2.3

附加链接:
有一篇文章正在做您想要实现的目标.我添加它作为示例,因为我不确定ModalPopup 在客户端如何工作:
http://mattberseth.com/blog/2007/07/confirm_gridview_deletes_with.html [ ^ ]

希望这能解决您的问题,并帮助您更好地了解事物的处理方式.

谢谢,
Hemant



Final Solution:
implement the changes in point 2 i.e. from 2.1 to 2.3

Additional Link:
there is an article doing exactly what you want to achieve. i''m adding it for an example and because i''m not sure how ModalPopup works at client end:
http://mattberseth.com/blog/2007/07/confirm_gridview_deletes_with.html[^]

Hope this will resolve your issue and help you better understand about how things gets processed.

Thanks,
Hemant


这篇关于数据列表itemcommand不触发?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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