|
Hi All,
I have a .aspx page like the code given below.
My question is can I identify the controls in the code behind.
i.e in my code behind it should identify like, i have one textbox and checkbox.
Please suggest me some idea....
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>
<title>
Ramkumar
("When you build bridges you can keep crossing them. ")
http://ramkumarishere.blogspot.com
|
|
|
|
|
You can iterate through the controls in the page's Control Collection.
Some ideas here: Dynamic Controls[^]
I don't speak Idiot - please talk slowly and clearly
'This space for rent'
Driven to the arms of Heineken by the wife
modified on Sunday, February 20, 2011 9:59 PM
|
|
|
|
|
Andy_L_J wrote: iterate through the controls in the page's Control Collection.
That won't work in this case unless the OP adds the runat="sever" attribute.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Hi,
If you wish to identify the Html controls in code behind, just add attribute runat="server" in them.
example:
<input id="Text1" runat="server" type="text" />
<input id="Checkbox1" runat="server" type="checkbox" />
then, you can access them in your code behind similar to the server controls.
|
|
|
|
|
Hi,
First what my goal is: I want when clicking on a button on my page a popup to appear with a list of images. When clicking on a image it should add som text (the name of the image) to a textbox on the page.
In first place I only try to let the popup appear when clicking the textbox because I don't know how to set the name of the image from the button.
My aspx code:
<table cellpadding="0" width="100%" border="0">
<tr>
<td style="text-align: right">
<asp:Label ID="lblMessage" runat="server" Text="<%$ Resources:Resource, Message %>"></asp:Label> : 
</td>
<td style="text-align: left; width: 510px">
<asp:TextBox Id="txtMessage" runat="server" onfocus="this.value = this.value;" MaxLength="250" Width="500px" />
</td>
<td style="vertical-align: top">
<asp:Button Id="btnSend" CssClass="button" runat="server" Text="<%$ Resources:Resource, Send %>" OnClientClick="SetScrollPosition()" OnClick="BtnSend_Click" />
</td>
<td style="width: 200px">
<asp:ImageButton ID="ibtnSmileys" runat="server" ImageAlign="AbsMiddle" ImageUrl="~/Images/Smiley_41_20_A.gif" />
<asp:Panel ID="panSmileys" runat="server" CssClass="chatSmileyPanel">
<asp:UpdatePanel ID="upanSmileys" runat="server">
<ContentTemplate>
<asp:DataList ID="dlstSmileys" runat="server" RepeatColumns="7" RepeatDirection="Horizontal" Width="100%" CellPadding="2" CellSpacing="2" OnItemCommand="dlstSmileys_ItemCommand">
<ItemTemplate>
<asp:ImageButton ID="ibtnSmiley" runat="server" ImageUrl='<%# Eval("Name", "../Images/Smileys/{0}") %>' CommandName="InsertSmiley" CommandArgument='<%# Eval("Name", "{0}").ToString() %>' />
</ItemTemplate>
</asp:DataList>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Panel>
<ajaxToolkit:PopupControlExtender ID="PopupControlExtender1" runat="server"
TargetControlID="txtMessage"
PopupControlID="panSmileys"
Position="Bottom"
CommitProperty="value"
OffsetX="3" OffsetY="3">
</ajaxToolkit:PopupControlExtender>
</td>
</tr>
</table>
My datalists ItemCommand:
protected void dlstSmileys_ItemCommand(object source, DataListCommandEventArgs e)
{
if (e.CommandName == "InsertSmiley")
{
string smileyName = Convert.ToString(e.CommandArgument);
txtMessage.Text += smileyName;
}
}
When I click an image in the popupcontrolextender it doesn't fire dlsSmileys_ItemCommand.....And I cann't figure out why?
If I instead of a datalist use a RadiobuttonList with some ListItems and click one of these items I get into the SelectedIndexChanged of the RadioButtonList....So I know with a RadiobuttonList it fires the command .......but why doesn't it with the DataList?
If you can suggest another way to accomplish my above goal your welcome to tell me about it. It doesn't matter in wich way I do the job.
Kind regards,
simsen
|
|
|
|
|
Do you have problem only for doesn't fire event?
sunaSaRa Imdadhusen
+91 99095 44184
|
|
|
|
|
I am new to Web development and am mucking around with creating controls on the fly and adding them to my page.
I create a GridView and bind it to a custom object.
Now how do I format the GridView as the rows are populated? For instance, set the column widths according to the cell contents?
Here is a code snippet:
Dim dgv As GridView = New GridView
dgv.ID = "dgv" & il.Div
dgv.Width = 592
dgv.DataSource = DTResults.GetShortResults(New Division(il.Id), s)
dgv.DataBind()
With dgv
.ForeColor = Drawing.Color.FromArgb(51, 51, 51)
.EnableModelValidation = True
.GridLines = GridLines.None
.CellPadding = 4
.Font.Size = 10
.Font.Name = "Arial"
.HeaderStyle.BackColor = Drawing.Color.FromArgb(80, 124, 209)
.HeaderStyle.Font.Bold = True
.HeaderStyle.ForeColor = Drawing.Color.White
.RowStyle.BackColor = Drawing.Color.FromArgb(239, 243, 251)
.AlternatingRowStyle.BackColor = Drawing.Color.White
End With
' add dgv to another control's Control collection
foo.Controls.Add(dgv)
I know how to do this using the OnRowDataBound attribute when creating a GridView at design time but here I am struggling.
Your suggestions are appreciared
I don't speak Idiot - please talk slowly and clearly
'This space for rent'
Driven to the arms of Heineken by the wife
|
|
|
|
|
Hi All,
I have a object with values and want to copy it in other object(which has same propery of source).
Please help me with this.
Ramkumar
("When you build bridges you can keep crossing them. ")
http://ramkumarishere.blogspot.com
|
|
|
|
|
Please do not cross post.
|
|
|
|
|
Does anybody see any problem running an APS.Net 2.0 application on more than one browser windows at the same time concurrently? Users are accessing the application with IE and they do Control+N and access the same application in another windows and use both windows concurrently. Would there be any issue coming from session or anything such that I need to be concerned? Thanks everyone.
|
|
|
|
|
It probably depends on how you are doing your session. If it is a server based session or using SQL on the server to store it, then you might be ok. If it is being kept locally, then you would have a separate session. It should be really easy to setup a test page where you set a variable and then have another button that reads that variable.
Steve Maier
|
|
|
|
|
I see a lot of people have been asking this question, some was because of the if postback check , but mine is different. i am using AjaxModalExtender to show my popup on the server side. this is my markup
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TestPage.aspx.cs" Inherits="PopTester.TestPage" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<style type="text/css">
.modalBackground
{ background-color: Yellow;
filter: alpha(opacity=60);
opacity: 0.6;
}
</style>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:Panel ID="Panel1" runat="server">
<asp:Button ID="Button1" runat="server"
Text="CreateModal" OnClick="Button1_Click" />
</asp:Panel>
<asp:Panel ID="ModalPanel" runat="server" Style="display: none" HorizontalAlign="Center" BackColor="Green">
<div>
<asp:UpdatePanel ID="Update" runat="server">
<ContentTemplate>
<asp:GridView ID="GridView1" AutoGenerateColumns="false" runat="server" Height="176px" Width="453px">
<Columns>
<asp:TemplateField HeaderText="ID">
<ItemTemplate>
<asp:CheckBox ID="chkId" runat="server" />
<asp:Label ID="lblId" runat="server" Text='<%#Eval("ID")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<asp:Label ID="lblname" runat="server" Text='<%#Eval("Name") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Lastname">
<ItemTemplate>
<asp:Label ID="lblLastname" runat="server" Text='<%#Eval("Lastname") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:Button ID="btnPickrecord" runat="server" Text="Pick Record"
onclick="btnPickrecord_Click " />
<asp:Button ID="btnload" runat="server" onclick="btnload_Click"
Text="Load Data" />
</ContentTemplate>
</asp:UpdatePanel>
</div>
<asp:Button ID="btnCancel" runat="server" Text="Close Me"
onclick="btnCancel_Click" />
</asp:Panel>
<asp:TextBox ID="txtreference" runat="server" AutoPostBack="True"></asp:TextBox>
<p>
</p>
</form>
</body>
</html>
as you can see i have a gridview that will be on the modal and its working fine, now after the grid has returned some results, i will select one record via the checkbox on the Grid and click the button "btnPickrecord" and this will fire my server side code
protected void btnPickrecord_Click(object sender, EventArgs e)
{
foreach (GridViewRow dataItem in GridView1.Rows)
{
CheckBox chkselect = (CheckBox)dataItem.FindControl("chkId");
if (dataItem.RowType == DataControlRowType.DataRow)
{
if (chkselect.Checked)
{
Label lblReferenceNumberID = (Label)dataItem.FindControl("lblId");
txtreference.Text = lblReferenceNumberID.Text;
}
}
}
}
the breakpoints got a hit and i stepped through it and i the value get assigned to the textbox txtreference.Text , but when i close the modal the textbox is empty , or while the modal is open i can see the value does not reflect in the parent page. Here is the Code for invoking the modal
protected void Button1_Click(object sender, EventArgs e)
{
AjaxControlToolkit.ModalPopupExtender modalPop = new AjaxControlToolkit.ModalPopupExtender();
modalPop.ID = "popUp";
modalPop.PopupControlID = "ModalPanel";
modalPop.TargetControlID = "Button1";
modalPop.DropShadow = true;
modalPop.BackgroundCssClass = "modalBackground";
modalPop.CancelControlID = "btnCancel";
this.Panel1.Controls.Add(modalPop);
modalPop.Show();
}
Thanks
Vuyiswa Maseko,
Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code.
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.com
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/
|
|
|
|
|
Hi,
This is because your textbox txtreference is outside the UpdatePanel.
You should understand the partial postback and how UpdatePanel works. Then you will yourself recognize why it is not updating your txtreference TextBox.
In summary, UpdatePanel updates only the partial content in UI.
For now, you can do your job by any of the 2 ways:
1. Either put your target TextBox also inside update panel. Or...
2. Do it using javascript by calling a javascript function in Sys.Application.add_load event.
For any details, you can google.
Hope this will help you.
|
|
|
|
|
I understand that , but i did not want to add it inside the Update Panel. I will figure out what to do.
thanks
Vuyiswa Maseko,
Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code.
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.com
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/
|
|
|
|
|
Then, you wish to consider the second approach mentioned:
Do it using javascript by calling a javascript function in Sys.Application.add_load event.
|
|
|
|
|
ok what i did i added another UpdatePanel and i set a trigger to be a Button on the First Update panel and that did the trick.
Thanks
Vuyiswa Maseko,
Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code.
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.com
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/
|
|
|
|
|
mates,
how to come up with tblTemp using programming not sql.
or any ideas how to get with tblTemp.
tblItem {ORIGINAL TABLE}
CDATE ITEMCODE ITEMVALUE
2008-12-08 1001 4.5
2008-12-08 1002 7.3
2008-12-08 1003 0.5
2009-03-25 1001 1.2
2009-03-25 1002 0.3
2009-03-25 1003 3.4
tblTemp {I WANT THE RESULT LIKE THIS!}
CDATE 1001 1002 1003
2008-12-08 4.5 7.3 0.5
2009-03-25 1.2 0.3 3.4
in access i just use looping
with ds.Fields.count - 1 (where ds is Recordset)
but how will i do it in asp.net using Dataset not Recordset
or something. ( I dont want to use recordset)
C# コードMicrosoft End User
2000-2008
「「「「「「「「「「「「「「「「「「「「「「「「「「「「
The best things in life are free
」」」」」」」」」」」」」」」」」」」」」」」」」」」」
|
|
|
|
|
C#Coudou wrote: any ideas how to get with tblTemp
You could try taking him/her to a movie, maybe dinner... see where it goes from there?
Seriously, though, I really don't understand your question. Why do you want to do it this way? Why don't you want to use SQL? SQL is infinitely better for querying data - that's what it does.
Please explain further?
|
|
|
|
|
GlobX wrote: Why don't you want to use SQL?
because i want to put in datatable as temptable not in sql, period.
and from datatable to gridview.
the problem is how will put in datatable.that is the question.
C# コードMicrosoft End User
2000-2008
「「「「「「「「「「「「「「「「「「「「「「「「「「「「
The best things in life are free
」」」」」」」」」」」」」」」」」」」」」」」」」」」」
|
|
|
|
|
Sorry, I still don't understand. I will leave this to someone else. Apologies.
|
|
|
|
|
ooppss. sorry. PROBLEM SOLVED. JUST IN TIME.
thanks anyway.
C# コードMicrosoft End User
2000-2008
「「「「「「「「「「「「「「「「「「「「「「「「「「「「
The best things in life are free
」」」」」」」」」」」」」」」」」」」」」」」」」」」」
|
|
|
|
|
C#Coudou wrote: PROBLEM SOLVED. JUST IN TIME.
thanks anyway.
Anyway it's better you close this question by posting the solution which you have find(Also clear the question too). Cheers.
|
|
|
|
|
You can create a datatable entirely in code, add the columns to it, and populate it, then just use it as if you had loaded it from a database.
Are you using C# or VB? I'll post a sample when I know which language you like.
Lisa Z. Morgan
|
|
|
|
|
Hi,
This is called Pivoting of Data.
Please have a look over my article: Pivoting DataTable Simplified[^]
This can get you a flexible and customized result with a clean code.
|
|
|
|
|
Good Evening My friends
I have been helping you , now its your turn to help
Due to Limitations in the Telerik, meaning that there is no nice Pop Control , and i want to create my own as i did in my previous article. I have used the DevExpress Popup Control and i have a Telerik Gridview inside it and i can nicely search for records and i can select the record from the Grid and i have a button that saves take an ID of that record like
protected void btnselect_Click(object sender, EventArgs e)
{
String Ref =null;
foreach (GridDataItem dataItem in grdactsandbills.MasterTableView.Items)
{
CheckBox chkselect = (CheckBox)dataItem.FindControl("chkselect");
if (chkselect.Checked)
{
Label lblReferenceNumberID = (Label)dataItem.FindControl("lblID");
Ref = lblReferenceNumberID.Text;
}
}
txtreferencenumber.Text = Ref;
}
this Button is in a PopupModal(DevExpress) , when this button is Clicked if assign that value to a textbox that is not part of the modal. and you can see i am doing it on the server side and the break point goes there and the watch shows that yes the value has been assigned to the textbox, but after i close the pop, the Textbox is empty. I am just buffled by this. Below is my markup
<asp:UpdatePanel ID="Update1" runat="server">
<ContentTemplate>
<asp:Panel ID="ModalPanel" runat="server" HorizontalAlign="Center" Style="display: none" BackColor="Green">
<br />
<asp:Label ID="Label7" runat="server"></asp:Label>
<asp:Button ID="btnCancel" runat="server" Text="Close Me" />
</asp:Panel><table class="style1">
<tr>
<td>
<asp:Button ID="btnadd" runat="server" Text="Add" onclick="btnadd_Click"
Height="31px" Width="63px" />
</td>
<td>
<asp:Button ID="btnsearch" runat="server" Text="Search"
onclick="btnsearch_Click" Height="33px" Width="77px"
onclientclick="ShowLoginWindow() ;" />
</td>
</table>
<dx:ASPxPopupControl ID="DevxPopup" runat="server"
PopupHorizontalAlign="WindowCenter" PopupVerticalAlign="WindowCenter"
ClientInstanceName="DevxPopup" ClientIDMode="AutoID"
CssFilePath="~/App_Themes/BlackGlass/{0}/styles.css" CssPostfix="BlackGlass"
SpriteCssFilePath="~/App_Themes/BlackGlass/{0}/sprite.css"
HeaderText=".:::Search:::." Modal="True" AllowDragging="True"
AllowResize="True" AppearAfter="100" CloseAction="CloseButton"
DragElement="Window" Width="100%">
<ContentCollection>
<dx:PopupControlContentControl runat="server">
<asp:Panel ID="Panel" runat="server">
<br />
<table class="style3">
<tr>
<td>
<asp:Label ID="Label6" runat="server" Style="Float:right" Text="Reference Number:"></asp:Label>
</td>
<td class="style4">
<asp:TextBox ID="txtRefNumber" runat="server"></asp:TextBox>
</td>
<td class="style6">
<asp:Button ID="Button2" runat="server" OnClick="btnsearch_Click"
Text="Search" />
</td>
<td>
<asp:Button ID="btnselect" runat="server" Height="27px"
OnClick="btnselect_Click" Text="Pick" Width="73px"
OnClientClick="GetValue();" />
</td>
</tr>
</table>
<br />
</asp:Panel>
<telerik:RadGrid ID="grdactsandbills" runat="server"
AllowFilteringByColumn="True" AllowMultiRowSelection="True" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False" GridLines="None"
ShowGroupPanel="True" Skin="Black">
<MasterTableView>
<Columns>
<telerik:GridTemplateColumn>
<ItemTemplate>
<asp:CheckBox ID="chkselect" runat="server"
/>
<asp:Label ID="lblID" runat="server" Text='<%# Eval("FilesID")%>'></asp:Label>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn HeaderText="Subject Title">
<ItemTemplate>
<asp:Label ID="lblSubjectTitleofbilActRef" runat="server"
Text='<%# Eval("Dateentered")%>'></asp:Label>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn HeaderText="Date Received">
<ItemTemplate>
<asp:Label ID="lblDateReceived" runat="server"
Text='<%# Eval("Dateneeded")%>'></asp:Label>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn HeaderText="Ministry ID">
<ItemTemplate>
<asp:Label ID="lblMinistryID" runat="server" Text='<%# Eval("Daysavailablebeforebringup")%>'></asp:Label>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn HeaderText="Date to AG">
<ItemTemplate>
<asp:Label ID="lblDatetoAGr" runat="server" Text='<%# Eval("Reasonsforbringup")%>'></asp:Label>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn HeaderText="Datereceived from AG">
<ItemTemplate>
<asp:Label ID="lblDatereceivedfromAG" runat="server"
Text='<%# Eval("Neededby")%>'></asp:Label>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn HeaderText="Date send M Signature">
<ItemTemplate>
<asp:Label ID="lblReferenceNumber" runat="server"
Text='<%# Eval("ReferenceNumber")%>'></asp:Label>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn HeaderText="Date send CS">
<ItemTemplate>
<asp:Label ID="lblDatesendCSr" runat="server" Text='<%# Eval("Dateentered")%>'></asp:Label>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn HeaderText="Date send HE signature">
<ItemTemplate>
<asp:Label ID="lblDatesendHEsignature" runat="server"
Text='<%# Eval("Enteredby")%>'></asp:Label>
</ItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
<CommandItemSettings ExportToPdfText="Export to Pdf" />
<RowIndicatorColumn>
<HeaderStyle Width="20px" />
</RowIndicatorColumn>
<ExpandCollapseColumn>
<HeaderStyle Width="20px" />
</ExpandCollapseColumn>
</MasterTableView>
<SelectedItemStyle BackColor="#FF9966" />
<ClientSettings AllowDragToGroup="True">
<Selecting AllowRowSelect="True" />
<Scrolling AllowScroll="True" UseStaticHeaders="True" />
<Animation AllowColumnReorderAnimation="True"
AllowColumnRevertAnimation="True" />
</ClientSettings>
</telerik:RadGrid>
</dx:PopupControlContentControl>
</ContentCollection>
</dx:ASPxPopupControl>
</ContentTemplate>
</asp:UpdatePanel>
Thanks
Vuyiswa Maseko,
Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code.
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.com
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/
|
|
|
|