- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
再次进入场景。总结如下:我有一个用户控件,它基本上是文本框、图像按钮、复选框列表的混合体,看起来像一个带有复选框的单选下拉列表……工作得很好。用户控件内的图像之一打开一个 aspx 页面作为弹出窗口。那里的功能很少,即保存值到数据库和东西。在弹出页面的“确定”按钮上单击,我应该能够将值保存到数据库中,并使用我保存到数据库中的值填充用户控件(充当下拉列表)。这里出现了问题,当尝试将复选框列表(存在于用户控件中)绑定(bind)到数据库中的值时,我收到错误消息,即复选框列表对象为空且尚未创建。我觉得在单击“确定”按钮时,用户控件必须刷新,因此复选框列表将处于事件状态。
PFB的相关代码:用户控件.ascx:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="SingleSelectCustomDropDown.ascx.cs" Inherits="MS.IT.Informa.UI.UserControls.SingleSelectCustomDropDown" %>
<asp:Panel ID="panel" runat="server">
<div id="FirstDiv">
<table>
<tr>
<td align="right">
<asp:TextBox ID="txtSelect" runat="server" ReadOnly="true"></asp:TextBox>
</td>
<td>
<asp:Image ID="imgShow" ImageUrl="../Images/DDGlyph.png" onmouseover="this.src='../Images/DDGlyphHOVER.png'" onmouseout="this.src='../Images/DDGlyph.png'" runat="server" />
</td>
</tr>
<tr>
<td colspan="2">
<div id="SecondDiv" style="display:none;">
<asp:CheckBoxList ID="chkBoxList" runat="server">
<asp:ListItem Value="0" Text="Standard" Selected="True"></asp:ListItem>
</asp:CheckBoxList>
</div>
<div id="ThirdDiv" style="display:none;">
<asp:ImageButton ID="btnNew" runat="server" Height="20px" ImageUrl="~/Images/new.png" Width="20px" OnClientClick="ShowPopup();" />
<asp:ImageButton ID="btnEdit" runat="server" Height="20px" ImageUrl="~/Images/edit.png" Width="20px" />
<asp:ImageButton ID="btnDefault" runat="server" Height="20px" ImageUrl="~/Images/default.png" Width="20px" />
<asp:ImageButton ID="btnDelete" runat="server" Height="20px" ImageUrl="~/Images/delete.png" Width="20px" />
</div>
</td>
</tr>
</table>
</div>
</asp:Panel>
<script type="text/javascript">
//Displays the divs containing checkboxlist and images
function ShowList() {
document.getElementById("SecondDiv").style.display = "block";
document.getElementById("ThirdDiv").style.display = "block";
}
//Hides the divs containing checkboxlist and images
function HideList() {
document.getElementById("SecondDiv").style.display = "none";
document.getElementById("ThirdDiv").style.display = "none";
}
//Displays the selected item from the checkboxlist into the textbox placed in the Custom Control
function DisplaySelectedItem(sender, txtBoxID) {
var x = document.getElementById(sender.id);
var chkBoxPrefix = sender.id + "_";
var selectedText;
for (i = 0; i < x.rows.length; i++) {
if(document.getElementById(chkBoxPrefix+i).checked)
{
selectedText = document.getElementById(chkBoxPrefix+i).parentNode.innerText;
}
}
document.getElementById(txtBoxID.id).value = selectedText;
}
//Ensures that only one item is selected from the checkboxlist
function SelectOnlyOneCheckBox(e) {
if (!e) e = window.event;
var sender = e.target || e.srcElement;
if (sender.nodeName != 'INPUT') {
return;
}
var checker = sender;
var chkBox = document.getElementById('<%= chkBoxList.ClientID %>');
var chks = chkBox.getElementsByTagName('INPUT');
for (i = 0; i < chks.length; i++) {
if (chks[i] != checker)
chks[i].checked = false;
}
}
function ShowPopup() {
window.open("ViewColumnOptions.aspx", "ViewColumnOptions", "height=300,width=600,left=300,top=150");
}
</script>
用户控件的隐藏代码如下:
public partial class SingleSelectCustomDropDown : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
chkBoxList.Attributes.Add("onclick", "SelectOnlyOneCheckBox(event);DisplaySelectedItem(this," + txtSelect.ClientID + ");HideList();");
txtSelect.Attributes.Add("onclick", "ShowList();");
imgShow.Attributes.Add("onclick", "ShowList();");
}
}
public void PopulateOtherViews()
{
SaveReportViewFilter<ReportFilterBase> newObj = new SaveReportViewFilter<ReportFilterBase>();
ViewColumnOptions vwobj = new ViewColumnOptions();
newObj.UserName = vwobj.Page.User.Identity.Name;
SaveReportView<ReportFilterBase> obj2 = new SaveReportView<ReportFilterBase>();
DataTable dt = obj2.GetSaveReportViewFromDataBase(newObj);
chkBoxList.DataSource = dt;//chkBoxList becomes null here..we have ample data in the datatable though
chkBoxList.DataTextField = dt.Columns[0].ToString();
chkBoxList.DataValueField = dt.Columns[0].ToString();
chkBoxList.DataBind();
}
}
函数 PopulateOtherViews 在单击 aspx 页面的按钮时被调用。下面是代码:
protected void btnOK_Click(object sender, EventArgs e)
{
if (chkSaveView.Checked)
{
if (!string.IsNullOrEmpty(txtViewName.Text))
{
//some code here to save the view name from txtViewName to the DB
SingleSelectCustomDropDown obj22 = new SingleSelectCustomDropDown();
obj22.PopulateOtherViews();
Page.ClientScript.RegisterStartupScript(this.GetType(),"close","CloseWindow();",true);
}
else
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "alertEnterViewName", "alertMessage('Please enter the view name');", true);
}
}
}
任何帮助、建议和指点都将不胜感激。问候阿努拉格
最佳答案
在 btnOK_Click 中,您正在创建用户控件的新实例,而不是将其附加到页面。我的建议是:
1.注册用户控件并添加到页面。
<%@ Register Src="~/UserControl/SingleSelectCustomDropDown.ascx" TagPrefix="uc1" TagName="SingleSelectCustomDropDown" %>
和...
<uc1:SingleSelectCustomDropDown runat="server" id="obj22" />
2.现在在后面的代码中修改:
protected void btnOK_Click(object sender, EventArgs e)
{
if (chkSaveView.Checked)
{
if (!string.IsNullOrEmpty(txtViewName.Text))
{
//some code here to save the view name from txtViewName to the DB
//Do not create the control again
//SingleSelectCustomDropDown obj22 = new SingleSelectCustomDropDown();
obj22.PopulateOtherViews();
Page.ClientScript.RegisterStartupScript(this.GetType(), "close", "CloseWindow();", true);
}
else
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "alertEnterViewName", "alertMessage('Please enter the view name');", true);
}
}
}
关于c# - 当控件从 aspx 页面传递时,用户控件内的复选框列表变为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17595112/
我正在与 svgpath 合作为了操作 svgs,我需要更改坐标系,使 y 变为 x,x 变为 y。我的问题是有什么办法可以做到这一点。我尝试围绕点 0 0 旋转并按图形的高度进行平移。 最佳答案 作
我有一个来源 Observable那: 注册一些 BroadcastReceivers当它订阅时 取消订阅时取消注册。 我只希望在订阅者数量从 0 增加到 1,或从 1 增加到 0 时发生订阅副作用。
def string_transf(): input('Enter a word or string') #letters = 'abcdefghijklmnopqrstvwxyz'
这个问题在这里已经有了答案: 关闭 12 年前。 Possible Duplicate: Format Number like StackoverFlow (rounded to thousands
我是 R 的初学者,有一个任务,我必须创建一个函数,其中所有数字都重新缩放,Inf 映射到 1,-Inf 映射到 0。我了解如何进行重新缩放,我只是不知道如何添加到函数中,所以 Inf 变为 1,-I
我有一个由二进制值组成的单字节字符数组,我试图将它拆分成一个二维 int 数组(低 nybble 和高 nybble)。这是我的代码: int nybbles[2][4]; //[0][] is lo
有人可以解释为什么 FLEX 4.5 XMLDecoder 对我的 XML 数据这样做吗? var decoder:XMLDecoder = new XMLDecoder; var $object:O
问题: 我在使用 scanf() 时遇到问题。我从阅读论坛之类的地方知道 scanf() 在 C 中有很多问题,但我只是还在学习基础知识,所以我不知道所有的细节。 我想解决的代码片段。 #includ
我遇到了一个问题,其中 UIViewController.navigationController 变为 nil,我正在拼命寻找这个问题的答案。 UINavigationController 在应用程
我在做this教程。 基本上我的问题是,在 front_is_clear 为 false 后,它运行 Jump_over_hurdle,然后停止。 from my_lib import * while
我正在实现一个简单的 Drag'n'Drop Bahevior。首先我要订阅鼠标事件: protected override void OnAttached() { b
这是我的代码的简化版本: template TIterator findMaximalPosition(TIterator begin, TIterator end) { TIterator
大家好,我有这个代码 function computeChange(){ var change; var amountDue = parseFloat(document.getElementById(
就像我的其他问题一样,非常不言自明。问题是,当用户没有选择银行时,变量 bankMoney 在第一次调用 payDay 时会变为 NaN。不选择,它应该通过我的 random 函数进行随机化,但我认为
当我登录时,我已通过身份验证,但当我切换到另一个页面时,req.isAuthenticated 返回 false,并且我位于登录面板上。第二件事是,当我登录时,我不断收到错误“发送后无法设置 head
下面一行 filterM (\x -> Just (x > 0)) [2, 1, 0, -1] 输出 Just [2,1] 和行 filterM (\x -> Just (x > 0)) [] 显示
这可以完美地使用整数进行拓扑排序,但是我想让它与作为参数的字符串类型兼容。有人对如何从这里更改数据结构有任何指导吗?或者我是否必须重写整个内容才能使 [add.edge("a","b");] 工作?我
我正在尝试调试此应用程序,但存在一个大问题。当我尝试将数组保存到数据文件时,一切正常。但是,如果我关闭应用程序并重新打开数组中的 bool 值,则变为 nil。这是保存数组的代码: NSString
程序运行时,有一系列的ListView窗体。我们用项目(作为字符串)填充其中之一,并检查选择状态是否已更改。更改后,我们使用 FocusedItem.Text 获取所选项目的文本。第一次工作得很好,但
我正在编写一个 WP 插件,它连接到另一个 WP 站点,并获取一些数据作为返回(一些强大的条目,带有名称和其他内容)。 一切都很好,我的插件基本上按预期工作 - 但我今天注意到它有一些奇怪的编码问题
我是一名优秀的程序员,十分优秀!