Is Possible To Set Control Properties Inside A Loop Without CodeBehind
Jan 11, 2011
Is it possible to set properties of an control inside a loop without using code behind? For example how can I set the Text property of the LinkButton inside the following loop at runtime, color being a POCO?
<table>
<%foreach (var color in GetColors()) {%>
<tr>
<td><asp:LinkButton runat="server" Text='<%# ??color.MyProperty?? %>' /></td>
</tr>
<%}%>
</table>
View 1 Replies
Similar Messages:
Nov 26, 2010
I need to access a control inside a repeater and change its properties. To enable it or not. I got an erorr message Object reference not set to an instance of an object. Here is my code inside a method. protected void
rptCAP_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
LinkButton lnDel = (LinkButton)rptCap.FindControl("lnkDelete");
lnkDel.Enabled = false; //<<<<< this is where the error occur
}
The name of the repeater control is id="rptCAP"
View 3 Replies
Feb 18, 2011
I have a webusercontrol with a flash control. I want to assign the movieurl from codebehind when the webusercontrol is registered in a new page.
<uc1:PopVideo
ID="PopVideo1"
runat="server"
/>
inside this webusercontrol I have a flash movie player that I can assign the movieurl in codebehind on the webusercontrol. The problem is that I need to assign the value from the new page the control is registered under. How can I access the flash control from the new page and assign the value?
View 2 Replies
Mar 29, 2011
Let us assume sample.aspx is a page this page contails the following Repeater
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<tr><td>
<asp:CheckBox ID="CheckBox1" runat="server" Text='<%# container.dataitem("CUISINENAME")%>' />
</td></tr>
</ItemTemplate>
</asp:Repeater>
My question is "while clicking the submit button in server side, i have to find the checkboxid which is placed inside the Repeater control.
View 1 Replies
Mar 19, 2010
I have a webpart that loads in a user control programmatically. Although the webpart has personalization properties that I can use and pass to the user control, I haven't found a way for the user control to be able to update the outer webpart's properties -- the user control knows nothing of its parent webpart except what it is given. When I try to use the [Personalizable] attribute on a property inside the user control, it doesn't work; it doesn't save anything to the personalization database. In a nutshell, I need the user control to be able to personalize its properties (e.g. for a date picker within the user control where the date has to be remembered between sessions) or to somehow be able to update its parent webpart's properties.
View 3 Replies
Jul 14, 2010
I have a composite control inside a repeater. I am trying to set the controls public properties inline like so (this is a simplified example):
<uc1:Control runat="server" ID="id" Value='<%# Eval("value") %>'>
When I place the repeater inside a user control INSIDE ANOTHER user control and onto the page this works - the property is correctly set, if I inspect it inside the EnsureChildControls() method of the custom control the composite control's Value propertyis set to Eval("value") as intended.
View 2 Replies
Dec 10, 2010
i have the following code below and was lookign to clean it up, but am not sure if it needs clean up or not.
foreach (SearchResult sr in mySrchColl)
{
string strValIn = sr.Properties["in"][0].ToString();
string strValOut= sr.Properties["out"][0].ToString();
}
do i change this to something like this:
string strValIn = "";
string strValOut= "";
foreach (SearchResult sr in mySrchColl)
[code]...
whats the difference or are these two identical?
View 6 Replies
Mar 25, 2011
how to increment anchor tag id inside for loop.
View 4 Replies
Oct 2, 2010
so I am using a foreach loop to iterate through comments. The comment section is wrapped inside "Comments" div. My function **DeleteComment** fetches comments again once you delete a comment and rebinds it to the control. However, after you delete a comment, anytime you try to delete another comment, the commentId of the very first deleted comment would keep getting passed to **DeleteComment** function instead of the passing the commentId of the comment you are trying to delete. If you refresh the page, then you can delete ONE comment again, and the same problem if you try to delete another.
View 1 Replies
Jan 5, 2010
I had the following code to send different mails to differnt users in my asp.net web application
foreach (DataRow dataRow in dataTable.Rows)
{
sendMails();
[code]...
View 8 Replies
Jul 30, 2010
I have a div with id="myDiv" and runat="server" inside a listview with id="lvItem".I need to access the div in code behind to add width of the div at runtime.How can I access the div from codebehid using C#?
View 2 Replies
Apr 29, 2010
Can somebody show me a better approach of looping through a Try -Catch statement. I have something like this:
Try
dbConn.Open()
Catch ex As Exception
errmsg = ex.Message
End Try
I need to try to connect 5 times before logging an error. My first thought was to nest Try - Catch 5 levels but I didn't like that idea. I'm sure there is better solution to it.
View 6 Replies
Mar 12, 2010
I have a problem that when i bring the array of asp and use it in the javascript, When i use the counter (i++) and print for each index of array just like "<%=app[i] %>" and it is not return the value back to me.i solve this problem for a dayedit
<%
String[] asp = {"a","b","c"};
%>
[code]...
View 1 Replies
Feb 8, 2011
I have a question about asp.net
I have this table with checkbox for each row:
[URL]
table code inside the ASPX page:
[URL]
So I'm trying to implement the delete selected button.. How exactly do i point to the specific checkbox for a particular row from codebehind when all 3 have the same name chkSelected? I know how to do it with a gridview, but not quite sure how if we do it with a for loop..
Can I do something like this inside btnDelete_Click?
[Code]....
View 1 Replies
Jul 15, 2010
I have a code like yis
for(int i=0;i<Count;i++)
{
k=item(i);
}
I want to add each value of 'k' to a gridview..If I have 10 values for 'k' (count=10), then I want to display a gridview with 10 rows...How can I do this?..
View 4 Replies
Mar 1, 2014
This is my for loop code, it is working fine , just the problem is, if there are 10 rows , it runs for 9 rows and not for 10th time? What correction is needed?
protected void gvouter_RowDataBound1(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
int count_rows_for_saving_answers = gvouter.Rows.Count;
for (int ii = 0; ii <= count_rows_for_saving_answers - 1; ii++)
{
Label lblsubid = (Label)gvouter.Rows[ii].FindControl("lblsubid");
[Code].....
View 1 Replies
Jan 30, 2010
I am trying to access accessing a control in a Formview. I have tried several methods, but nothing seems to work
[Code]....
[Code]....
View 6 Replies
Sep 30, 2010
I'm trying to delete a bunch of records in mysql. The record info to delete (userid, name) is stored in an arraylist. It seems to only delete the first record and gives an error ("Transaction has already been rolled back or is not pending.") afterwards. I have the transaction commit inside the loop which I think is the issue but not sure how to go further if I bring it outside of the loop. Here's the relevant bits of the code.
try
{
ArrayList alist = new ArrayList();
//alist gets populated with data like (12345,robot)(23456,car) here.
MySqlConnection conn2 = new MySqlConnection(query_connection);
conn2.Open();
MySqlCommand command2 = conn2.CreateCommand();
MySqlTransaction mytransaction;
mytransaction = conn2.BeginTransaction();
command2.Transaction = mytransaction;
for (int i = 0; i < alist.Count; i++)
{
string[] s = alist[i].ToString().Split(',');
try
{
command2.CommandText = "DELETE from users_settings WHERE UserID=" + s[0].ToString();
command2.ExecuteNonQuery();
command2.CommandText = "DELETE from users WHERE ID=" + s[0].ToString();
command2.ExecuteNonQuery();
mytransaction.Commit();
}
catch (Exception e){
mytransaction.Rollback();
}
}
}
catch(Exception e){
}
View 1 Replies
Mar 28, 2010
I have a GridView, the first column it's a RadioButton template and the second it's a DropDownList Template, the number of rows depends on the user, I mean they are not static. I'm using the following JS function to get the row selected with the radiobuttons:
[Code]....
With this function I know which RadioButton was selected, now, I would like to get the DropDownList value or text of the selected row, I know I have to loop through every DropDownList to get an array of controls, but since they are something like ctl00_ContentPlaceHolder1_GVProducts_ctl02_DValsDropDown, I just don't know how to achive this through JS.
View 3 Replies
Jan 13, 2011
In my application I have panel which has 5 textboxes. I've written several functions for checking each of textbox if the entered value is ok (number, is this number in database, etc.). If error occurrs textbox which caused it has different color of background.
However I wanted to write (add) function which will check if one of the textboxes has the same value as other. The problem is that function is checking blank textboxes, although it shouldn't - I wrote if statement which allows checking only non-blank textboxes but it doesn't work.
View 22 Replies
Mar 1, 2011
how can i set DateFormatString inside GridView column in codebehind page?
View 6 Replies
Feb 16, 2011
ive created my own custom control, now in the code behind of the custom control file i can add Name.Click += new EventHandler(name); but on the codebehind of the page where ive used the custom control i cannot, is there anyway i can regsiter it as an available attribute to add? my code below and on the image the test codebehind click is not available, how can i get it?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class LargeButton : System.Web.UI.UserControl
{
public string JSFunc { get; set; }
public string SSFunc { get; set; }
public string ImgName { get; set; }
public string LinkText { get; set; }
protected void Page_Load(object sender, EventArgs e)
{
Link.Attributes.Add("onclick", "javascript:"+ JSFunc + ";");
Link.HRef = "javascript:;";
Link.Title = LinkText;
Img.Src = "~/App_Themes/" + Page.Theme + "/Images/Icons32/" + ImgName;
Img.Alt = LinkText;
//Link.ServerClick += new EventHandler(asd);
}
}
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="LargeButton.ascx.cs" Inherits="LargeButton" %>
<a ID="Link" runat="server" class="MenuItemLarge" clientidmode="Static" >
<img ID="Img" align="center" runat="server"/>
<br />
<%= LinkText %>
</a>
<MB:LgButton runat="server" ID="Save"
JSFunc="Save(this)"
ImgName="save_32.png"
LinkText="Save" />
View 4 Replies
Apr 4, 2010
I have a custom server control inheriting from CompositeControl. It consists of two RadioButtonlist controls that are rendered side by side in an html table. The number of ListItems in each RadioButtonList is not known until runtime. Depending on how many items each list contains, the RepeatColumns property of each list is set differently. To do this in the handler for the ItemDataBound event I need to get the count of ListItems in each RadioButtonList. How do I expose the Items.Count property of each internal RadioButtonList as a top-level property? I tried using a getter to return the count but this generates a compile-time error to the effect that the count cannot be assigned to--even though I have not created a setter.
Similarly, in the handler for the Submit event, I need to get the ClientID of each internal RadioButtonList to pass to a method that checks for data changes. How do I expose the ClientID of each component RadioButtonList as a top-level property?
I can of course index the Controls collection of the composite control to access the child control and read its properties--but that defeats the whole point of making a complex, independent custom server control.
View 1 Replies
Nov 11, 2010
I am creatin a server control where some controls are being rendered inside `protected override void Render(HtmlTextWriter writer)`
writer.AddAttribute(HtmlTextWriterAttribute.Type, "button");
writer.AddAttribute(HtmlTextWriterAttribute.Id, this.UniqueID + "butto_Foo1");
writer.AddAttribute(HtmlTextWriterAttribute.Value, "Button1");
writer.RenderBeginTag(HtmlTextWriterTag.Input);
writer.RenderEndTag(); //button
writer.AddAttribute(HtmlTextWriterAttribute.Type, "button");
writer.AddAttribute(HtmlTextWriterAttribute.Id, this.UniqueID + "butto_Foo2");
writer.AddAttribute(HtmlTextWriterAttribute.Value, "Button2");
writer.RenderBeginTag(HtmlTextWriterTag.Input);
writer.RenderEndTag(); //button
This way buttons are rendered on design view as well. The problem is that number of buttons to render is dynamic based on data in xml file (even if the data was static, the number of button is about 12 and I don't think it is wise to copy paste the same code above 6 times...). I thought by using loop for that:
int i = 1;
foreach (Button button in tb.Items)
{
writer.AddAttribute(HtmlTextWriterAttribute.Type, "button");
writer.AddAttribute(HtmlTextWriterAttribute.Id, this.UniqueID + "butto_Foo" + i);
writer.AddAttribute(HtmlTextWriterAttribute.Value, button.ButtonValue);
writer.RenderBeginTag(HtmlTextWriterTag.Input);
writer.RenderEndTag(); //button
i++;
}
tb is defined in OnLoad; On run time it works, but on design time I get error: > Error rendering control. And control is not being rendered.
View 1 Replies
Mar 22, 2011
I am grabbing an XML feed an throwing it into a dataset. I am looping through the datatable that is in the dataset and adding a column to the datatable (Distance) that is the result of a calculation. What I then need to do is sort the dataset on the new column (Distance) I added, but it is not working... Here is a sample of my code.
[Code]....
View 1 Replies