ASP回来后的问题,HTML控件 [英] asp post back issue and html controls

查看:138
本文介绍了ASP回来后的问题,HTML控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的HTML。

<input id="rdb1"  type="radio" name="rdbData" checked="checked" />
<input id="rdb2"  type="radio" name="rdbData" />
<asp:Button ID="btnTest" runat="server" Text="Test" OnClick="btnTest_Click" />

按钮仅 ASP:按钮,但单选按钮是not.First时候选择页面加载RDB1 。但是当我点击按钮为btnTest 与检查 RDB2 ,刷新页面,并选择1 redio button.To prevent这个我尝试的jQuery 这样。
的document.ready :结果

Button is only asp:button but radio buttons are not.First time when page is load rdb1 is selected.But when i click the button btnTest with check rdb2, page is refreshed and select 1st redio button.To prevent this i try jquery like this. Inside Document.ready:

var btnTest = "<%=btnTest.ClientID %>";
 $('#' + btnTest).bind("click", function() {
            if ($('#rdb1').attr("checked")) {
                $('#rdb2').attr("checked", false);
                $('#rdb1').attr("checked", true);

            }
            else {
                $('#rdb1').attr("checked", false);
                $('#rdb2').attr("checked", true);
            }
        });

但它不是我们work.How可以处理这种类型的situation.Where的我得到wrong.Any想法或任何alternative.Thanks。

But its not work.How can we handle this type of situation.Where i am getting wrong.Any idea or any alternative.Thanks.

推荐答案

我再说一遍,要求是荒谬的。他们将如何告诉你使用的服务器端控件不反正在code期待。这就好比要求你写用筷子什么的code。

I repeat that the requirement is ABSURD. How are they going to tell you used server-side controls without looking at the code anyway. This is like requiring that you write the code using chopsticks or something.

但只是作为一个练习,我提供了以下解决方案:

However just as an exercise I provide the following solution:

<input id="rdb1"  type="radio" name="rbdData" value="rbd1" <%= Rdb1Checked %> />
<input id="rdb2"  type="radio" name="rbdData" value="rbd2" <%= Rdb2Checked %> />
<asp:Button ID="btnTest" runat="server" Text="Test" onclick="btnTest_Click" /> 

和背后的code:

protected string Rdb1Checked
{
    get
    {
        if (IsPostBack)
        {
            if (Request["rbdData"] == "rbd1")
            {
                return "checked";
            }
            else
            {
                return "";
            }
        }

        return "checked";
    }
}

protected string Rdb2Checked
{
    get
    {
        if (IsPostBack)
        {
            if (Request["rbdData"] == "rbd2")
            {
                return "checked";
            }
            else
            {
                return "";
            }
        }

        return "";
    }
}

问他们为什么有这些要求。也许他们不希望看到这种情况下,您可以设置的ClientIDMode为静态,避免自动生成的ID的客户端ID。你可以通过设置为null,等等。也许他们不喜欢单选按钮什么Web表单呈现在其中使用服务器端输入的情况下将被确定完全删除它们。对自己根本要求是没有意义的。

Ask why they have these requirements. Maybe they don't want to see the client IDs in which case you may set the ClientIDMode to Static and avoid auto generated IDs. You can remove them completely by setting them to null, etc. Maybe they don't like what Web Forms renders for Radio buttons in which case using server side inputs would be OK. The requirement on its own simply does not make sense.

这篇关于ASP回来后的问题,HTML控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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