我有一个转发器,显示与帖子相关的评论.
我想添加一些功能,当用户点击它来自的链接时:
报道这篇文章
至
帖子已被标记
如何访问特定的lnkButton?显然在ItemDataBound中这很容易完成,但是在click方法中我不知道怎么做.
我是否需要做以下事情:
我试过这样的事情;
LinkButton lb = repeater.FindControl(LINK_BUTTON_UNIQUE_ID) as LinkButton;
lb.Text = "blah blah blah";
Run Code Online (Sandbox Code Playgroud)
但lb总是为空.
任何帮助将不胜感激,谢谢!
我创造了
<input type="checkbox" id="test" >
Run Code Online (Sandbox Code Playgroud)
使用文字.现在我想得到这个控制,所以我可以检查它是否检查.如何在aspx.cs页面中找到此控件?
我现在在回发时使用Literal创建了复选框我得到了复选框Request.form.Allkeys.但是我不知道如何阅读这些值如何使用它们?我如何计算那里有多少个值,如何在那里找到一些值我希望找到的例子如果request.forum.allkey包含forumaName0..
谢谢
我有一个用户控件我正在构建(ASP.NET 3.5,使用C#).
这个控件很大程度上基于另一个类似的控件(不幸的是,剪切和粘贴继承,但是没有简单的方法来抽象它).给我带来麻烦的行直接从其他控件复制,就像显示器的大部分一样.
相关的代码行如下:
Panel pnlForm = (Panel)e.Item.FindControl("pnlForm");
Literal ltrAvailableCount = (Literal)e.Item.FindControl("ltrAvailableCount");
DropDownList drpLanguage = (DropDownList)pnlForm.FindControl("drpLanguage");
DropDownList drpShipTo = (DropDownList)pnlForm.FindControl("drpShipTo");
HiddenField hdnAvailableProductId = (HiddenField)pnlForm.FindControl("hdnAvailableProductId");
DropDownList drpQuantity = (DropDownList)pnlForm.FindControl("drpQuantity");
HiddenField hdnSelectedStyle = (HiddenField)e.Item.FindControl("hdnSelectedStyle");
Label lblStyleName = (Label)e.Item.FindControl("lblSelectedStyle");
Run Code Online (Sandbox Code Playgroud)
pnlForm在上面找到了正确的,原样ltrAvailableCount.
如果我跳过drpQuantity,它和以下行正常工作.然而,当我运行的线路drpLanguage,drpShipTo或hdnAvailableProductId FindControl将引发NullReferenceException.
我并不是说它返回'null'并且我尝试访问返回对象的属性,该方法FindControl抛出异常.根据MSDN库,这是不可能的 - FindControl不会将任何内容列为潜在的抛出错误,它只是说如果它找不到Control,它将返回null.
什么可能导致FindControlNullReferenceException?
- - - - - - - - -编辑 - - - - - - - -
我还要提一下,如果我在即时窗口中运行三个有问题的行中的任何一行,我会得到正确的结果.我还可以看到在该控制ControlCollection …
我想GridView在一个单独的类中找到一个控件,但我在这样做时遇到了问题。我什至尝试将我的代码放在 aspx.cs 页面中,但无济于事。我不断收到未将对象引用设置为对象实例的情况。我确定我遗漏了一个简单的步骤,但在我的研究中我似乎找不到任何东西。
<asp:GridView ID="GridView1" EnableViewState="true"
runat="server"
BackColor="White" BorderColor="#CC9966"
BorderStyle="None" BorderWidth="1px" CellPadding="4" Width="933px"
onrowdatabound="GridView1_RowDataBound"
onrowdeleting="GridView1_RowDeleting"
onrowediting="GridView1_RowEditing"
onrowupdating="GridView1_RowUpdating"
onsorting="GridView1_Sorting"
AllowSorting="true"
AutoGenerateColumns="False"
PersistedSelection="true" onrowcancelingedit="GridView1_RowCancelingEdit">
<EditRowStyle Font-Size="Small" Width="100px" />
<FooterStyle BackColor="#FFFFCC" ForeColor="#330099" />
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton runat="server" ID="EditLinkButton" CausesValidation="True"
Text="Edit" CommandName="Edit"/>
<asp:LinkButton runat="server" ID="DeleteLinkButton" CausesValidation="False"
Text="Delete" CommandName="Delete"/>
</ItemTemplate>
<EditItemTemplate>
<asp:LinkButton runat="server" ID="UpdateLinkButton" CausesValidation="True"
Text="Update" CommandName="Update"/>
<asp:LinkButton runat="server" ID="CancelLinkButton" CausesValidation="False"
Text="Cancel" CommandName="Cancel"/>
</EditItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Run Code Online (Sandbox Code Playgroud)
protected void Page_Load(object sender, EventArgs e) {
SetDirectory();
System.Web.UI.Page page = (System.Web.UI.Page)System.Web.HttpContext.Current.Handler; …Run Code Online (Sandbox Code Playgroud) 我在页面上有一个ASP登录控制框,它是自定义的.
在Login控件中,我们有用户名和密码文本框.
我想找到带有javascript函数的用户名和密码控件.
var Username= document.getElementById("<%=UserName.ClientID%>");
Run Code Online (Sandbox Code Playgroud)
但是这段代码没有编译并且给出了编译时错误
UserName not found in this context.
Run Code Online (Sandbox Code Playgroud)
如果我写客户端id:
var username = document.getElementById("login_LoginUser_UserName");
Run Code Online (Sandbox Code Playgroud)
它正确执行,但我想找到客户端ID,而不是在这里使用硬编码的ID.
我需要在我的 asp.net 应用程序的中继器中找到一个控件。
目前我正在使用,FindControl("IdOfControl")并且运行良好。
但是我需要按类型 ( ImageButton)找到一个控件。
我目前的代码:
For Each rptItem As RepeaterItem In myRepeater.Items
Dim imgBtn As ImageButton = TryCast(rptItem.FindControl("myImageBtn"), ImageButton)
AddHandler imgBtn.Click, AddressOf imgBtn_Click
Next
Run Code Online (Sandbox Code Playgroud)
我正在寻找类似的东西:
For Each rptItem As RepeaterItem In myRepeater.Items
Dim imgBtn As ImageButton = TryCast(rptItem.FindControl(TypeOf ImageButton), ImageButton)
AddHandler imgBtn.Click, AddressOf imgBtn_Click
Next
Run Code Online (Sandbox Code Playgroud)
有人可以帮忙吗?
我现在尝试搜索几个小时,但无法找出为什么我的代码(又名我)失败了
基本上......我有一个listview控件,我正在传递产品的数据表(ID,名称,描述和价格列),并且我试图使它在按下"结帐"按钮时,它会解析所有页面上的控件,找到具有正确ID的所有控件,并将项值添加到购物车.
我已经检查了源代码中的所有ID,它们与FindControl方法请求的ID匹配.
被抛出的错误是:
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Line 21: For I = 1 To counter
Line 22: Dim cartItem As New Core.Types.CartItem
Line 23: cartItem.Name = CType(productsContainer.FindControl("product" + I.ToString()), HtmlGenericControl).InnerText
Line 24: cartItem.Quantity = Convert.ToInt32(CType(productsContainer.FindControl("quantity" + I.ToString()), HtmlSelect).Value)
Line 25: cartItem.Price = …Run Code Online (Sandbox Code Playgroud) 转发器标记:
<asp:Repeater ID="Repeater_sorular" runat="server" OnItemCommand="Repeater_sorular_ItemCommand"
OnItemDataBound="Repeater_sorular_ItemBound">
<HeaderTemplate>
</HeaderTemplate>
<ItemTemplate>
<table>
<tr>
<td>
<rad:RadChart ID="RadChart1" runat="server" DefaultType="Pie" Width="700">
<PlotArea Appearance-FillStyle-FillType="Gradient" Appearance-FillStyle-MainColor="#D90420"
Appearance-FillStyle-SecondColor="#FFAD4A" Appearance-Border-Visible="false">
<EmptySeriesMessage>
<TextBlock Text="Seçilen anket henüz oylanmam??t?r.">
<Appearance TextProperties-Font="Tahoma, 10pt, style=Bold">
</Appearance>
</TextBlock>
</EmptySeriesMessage>
</PlotArea>
<ChartTitle>
<TextBlock Appearance-TextProperties-Font="Tahoma">
</TextBlock>
</ChartTitle>
<Appearance ImageQuality="HighQuality" Border-Color="#DFDDDD" TextQuality="ClearTypeGridFit">
</Appearance>
<Series>
<rad:ChartSeries Type="Pie" Appearance-TextAppearance-TextProperties-Color="#FFFFFF"
Appearance-TextAppearance-TextProperties-Font="Tahoma">
</rad:ChartSeries>
</Series>
<Legend Visible="True">
<TextBlock Visible="True">
</TextBlock>
</Legend>
</rad:RadChart>
</td>
<td>
<div style="font-weight: bolder; padding: 5px;">
<%#(((RepeaterItem)Container).ItemIndex+1).ToString() %>.
<%#Eval("Subject")%>
</div>
<asp:BulletedList ID="BulletedList_secenekler" runat="server" DataSource='<%#Eval("Secenekler")%>'
DataTextField="OptionName" DataValueField="OptionId" CssClass="sira_numarali">
</asp:BulletedList>
</td> …Run Code Online (Sandbox Code Playgroud) 我有一个中继器,嵌套有 Html 表行:
<asp:Repeater ID="Repeater1" runat="server" OnItemDataBound="Repeater1_ItemDataBound">
<HeaderTemplate>
<table id="grid">
<thead>
<tr>
<th>SID</th>
<th>Start Date</th>
<th>End Date</th>..
<th>PDF Text</th>
</tr>
</thead>
<tbody>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><%#DataBinder.Eval(Container.DataItem,"ID") %></td>
<td><%#DataBinder.Eval(Container.DataItem,"startDate") %></td>
<td><%#DataBinder.Eval(Container.DataItem,"endDate") %></td
<td>
<asp:LinkButton runat="server" ID="lbtnPDF" Text="PDF Full Text" OnClick="lbtnPDF_Click" />
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</tbody>
</table>
</FooterTemplate>
</asp:Repeater>
Run Code Online (Sandbox Code Playgroud)
当用户单击链接按钮时,我想获取该行中继器项目的 ID,并将在另一个 aspx 页面中显示与该 ID 相关的 PDF 文件。
我在 itemdatabound 事件上写道:
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
LinkButton lnkBtn = (LinkButton)e.Item.FindControl("lbtnPDF");
}
Run Code Online (Sandbox Code Playgroud)
如何获取嵌套在 html 表中的中继器的列 ID?
asp.net ×10
findcontrol ×10
repeater ×4
c# ×3
vb.net ×2
.net ×1
gridview ×1
javascript ×1
listview ×1
master-pages ×1
types ×1