Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在按钮onClick事件后继续显示:inline?_C#_Asp.net - Fatal编程技术网

C# 如何在按钮onClick事件后继续显示:inline?

C# 如何在按钮onClick事件后继续显示:inline?,c#,asp.net,C#,Asp.net,我使用按钮onClick激活显示:使用更新面板中dropdownlist1的onchange事件将textbox2与其他dropdownlist2内联,并将值发送到服务器 在服务器的page_load部分中读取dropdownlist1的值,以继续显示:dropdownlist2和textbox2按钮的内联处理onclick事件发生,页面呈现并再次作为display:none处理 调试确认正确输入了dropdownlist1值,并且执行了display:inline code of dropdo

我使用按钮onClick激活显示:使用更新面板中dropdownlist1的onchange事件将textbox2与其他dropdownlist2内联,并将值发送到服务器

在服务器的page_load部分中读取dropdownlist1的值,以继续显示:dropdownlist2和textbox2按钮的内联处理onclick事件发生,页面呈现并再次作为display:none处理

调试确认正确输入了dropdownlist1值,并且执行了display:inline code of dropdownlist2,我不知道为什么

script

        function DisplayDate(ddlDate) {
            var Control = document.getElementById(ddlDate.id);

            if (Control.value == 2) {
                document.getElementById('ctl00_ContentPlaceHolder1_ddlSearch_Date').style.display = 'inline';
            }
            else {
                document.getElementById('ctl00_ContentPlaceHolder1_ddlSearch_Date').style.display = 'none';
                document.getElementById('ctl00_ContentPlaceHolder1_txtDate1').style.display = 'none';
                document.getElementById('ctl00_ContentPlaceHolder1_txtDate2').style.display = 'none';
            }
        }

aspx
    <asp:UpdatePanel ID="updSearch" runat="server">
        <ContentTemplate>

            <div>
                <asp:DropDownList ID="ddlSearch_Type" runat="server" CssClass="btn btn-outline btn-primary dropdown-toggle" onchange="DisplayDate(this)">
                </asp:DropDownList>

                <asp:DropDownList ID="ddlSearch_Date" runat="server" CssClass="btn btn-outline btn-primary dropdown-toggle" Style="display: none;">
                </asp:DropDownList>

                <asp:TextBox ID="txtDate1" runat="server" placeholder="Search..." TextMode="Date" CssClass="form-control text-1" Width="150px" Style="text-align: center; display: none;"></asp:TextBox>
                <asp:TextBox ID="txtDate2" runat="server" placeholder="Search..." TextMode="Date" CssClass="form-control text-1" Width="150px" Style="text-align: center; display: none;"></asp:TextBox>

                <asp:LinkButton ID="lnkSearch2" runat="server" OnClientClick="Searching();" CssClass="btn btn-primary text-1 p-2" Style="height: 37px; text-align: center; display: inline;"><i class="fas fa-search m-0"></i></asp:LinkButton>
            </div>
        </ContentTemplate>
    </asp:UpdatePanel>

page_load

if(ddlSearch_Type.SelectedValue == "1")
                {
                    ddlSearch_Type.Attributes.Add("display", "inline");
                    txtDate1.Attributes.Add("display", "inline");
                    txtDate2.Attributes.Add("display", "inline");
                }
脚本
函数显示日期(ddlDate){
var Control=document.getElementById(ddlDate.id);
如果(Control.value==2){
document.getElementById('ctl00_contentplaceholder 1_ddlSearch_Date')。style.display='inline';
}
否则{
document.getElementById('ctl00_contentplaceholder 1_ddlSearch_Date')。style.display='none';
document.getElementById('ctl00_ContentPlaceHolder1_txtDate1')。style.display='none';
document.getElementById('ctl00_contentplaceholder 1_txtDate2')。style.display='none';
}
}
aspx
页面加载
如果(ddlSearch_Type.SelectedValue==“1”)
{
ddlSearch_Type.Attributes.Add(“显示”、“内联”);
添加(“显示”、“内联”);
添加(“显示”、“内联”);
}
而不是您的代码

if(ddlSearch_Type.SelectedValue == "1")
                {
                    ddlSearch_Type.Attributes.Add("display", "inline");
                    txtDate1.Attributes.Add("display", "inline");
                    txtDate2.Attributes.Add("display", "inline");
                }
你需要把它改成

if(ddlSearch_Type.SelectedValue == "1")
                {
                    ddlSearch_Type.Style.Add("display", "inline");
                    txtDate1.Style.Add("display", "inline");
                    txtDate2.Style.Add("display", "inline");
                }
因为显示是样式属性而不是html属性