I have 2 textboxes on an Asp.net(with c#) page and I cannot see this fields from cs class.
In aspx:
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<ajaxToolkit:ToolkitScriptManager runat="server"></ajaxToolkit:ToolkitScriptManager>
<div>
<table>
<tr>
<td style="width:40%"> <asp:Label ID="lblFullname" runat="server" Text="Fullname" ></asp:Label></td>
<td style="width:20%"> </td>
<td style="width:40%">
<asp:TextBox ID="txtFullname" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td style="width:40%"> <asp:Label ID="lblBirthDate" runat="server" Text="BirthDate" ></asp:Label></td>
<td style="width:20%"> </td>
<td style="width:40%">
<asp:TextBox ID="txtBirthDate" runat="server" Text="" ></asp:TextBox>
<ajaxToolkit:MaskedEditExtender ID="MaskedEditExtenderBirthDate" TargetControlID="txtBirthDate" runat="server"
UserDateFormat="DayMonthYear" Mask="99/99/9999" MaskType="Date" ></ajaxToolkit:MaskedEditExtender>
</td>
</tr>
<tr><td colspan="3" style="float:right"><asp:Button Text ="Save" runat="server" ID="btnSave" OnClick="btnSave_Click"/> </td></tr>
</table>
</div>
And I am trying to get value from the txtFullname.I try txtFullname.Text and this.txtFullname but the application cannot see this values .
Can somebody how can I get the value for that textbox?
Please check if you have specified the codebehind file name correctly.
This could be one of the issues for not getting the control name
inside the code file.
If that isn't working for you, please use the below code for reference.
You have not included your "Register" directive. So, I took to privilege to give my own.
Change your markup to:
<%# Page Title="Home Page" Language="vb" MasterPageFile="~/Site.Master" AutoEventWireup="false"
CodeBehind="Default.aspx.vb" Inherits="WebApplication2._Default" %>
<%# Register TagPrefix="asp" Namespace="AjaxControlToolkit" Assembly="AjaxControlToolkit" %>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="Server" />
<div>
<table>
<tr>
<td style="width: 40%">
<asp:Label ID="lblFullname" runat="server" Text="Fullname"></asp:Label>
</td>
<td style="width: 20%">
</td>
<td style="width: 40%">
<asp:TextBox ID="txtFullname" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td style="width: 40%">
<asp:Label ID="lblBirthDate" runat="server" Text="BirthDate"></asp:Label>
</td>
<td style="width: 20%">
</td>
<td style="width: 40%">
<asp:TextBox ID="txtBirthDate" runat="server" Text=""></asp:TextBox>
<asp:MaskedEditExtender id="MaskedEditExtenderBirthDate" targetcontrolid="txtBirthDate"
runat="server" userdateformat="DayMonthYear" mask="99/99/9999" masktype="Date"></asp:MaskedEditExtender>
</td>
</tr>
<tr>
<td colspan="3" style="float: right">
<asp:Button Text="Save" runat="server" ID="btnSave" OnClick="btnSave_Click" />
</td>
</tr>
</table>
</div>
</asp:Content>
This code has been tested and is working.
The table tag is missing runat="server" attribute. Add it in the tag. You should be able to see the fields in cs file
Are you trying in master page or the page file ? It should work with runat="server"
You code is showing that you are using the content page which must use the master page. so you should check following things to resolve this issue.
You page must contain the Page directive similar to following one. <%# Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeFile="Default.aspx.cs" Inherits="_Default" %>
Codebehind file name must be correct like page Default.aspx and Default.aspx.cs
You must use runat="server" to make control accessible at server side.
Related
this is my code to view products as list view inside each item in list view i want to view list of items how can i do this? i can not understand the concept of the eval function and i want to know if i can pass to it list items from code behind without data Bind or it basically depends on data-bind ?
<asp:ListView ID="mylistView" runat="server" GroupItemCount="3">
<EmptyDataTemplate>
<table id="Table2" runat="server">
<tr>
<td>
No data was returned.
</td>
</tr>
</table>
</EmptyDataTemplate>
<EmptyItemTemplate>
<td id="Td3" runat="server" />
</EmptyItemTemplate>
<GroupTemplate>
<tr id="itemPlaceholderContainer" runat="server">
<td id="itemPlaceholder" runat="server">
</td>
</tr>
</GroupTemplate>
<ItemTemplate>
<table border="0" width="300" style="display: inline-block; background-color: Lime;">
<tr>
<td>
 
</td>
<td>
<a href='ContactUs.aspx'>
<image src='productsImg/<%# Eval("Pic_Path") %>' width="100" height="75" border="0">
</a> 
</td>
<td>
<a><b style="text-decoration: underline;">
<%# Eval("MenuName") %></b> </a>
<br />
want to view here list of items
I
</td>
</tr>
</table>
</ItemTemplate>
<LayoutTemplate>
<table id="Table1" runat="server">
<tr id="Tr1" runat="server">
<td id="Td1" runat="server">
<table id="groupPlaceholderContainer" runat="server">
<tr id="groupPlaceholder" runat="server">
</tr>
</table>
</td>
</tr>
<tr id="Tr2" runat="server">
<td id="Td2" runat="server">
</td>
</tr>
</table>
</LayoutTemplate>
</asp:ListView>
this is code behind...
dataSource.ConnectionString = connetionString;
dataSource.SelectCommand = "SELECT * FROM tbl_WebMenu where MenuID like'3_';";
mylistView.DataSource = dataSource;
mylistView.DataBind();
thanks in advance.
Eval is used to bind to an UI control that is supposedly read only. it can be used to set any type of property of control.
The complete syntax is "Databinder.Eval", it has to be used in conjunction with databind.
Look at this example.
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="lblRead" runat="server" Text='<%# Eval("FieldName") %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
you can even set a property of control using eval. it provides flexibility.
But there is a downside of eval as it uses reflection to evaluate the expression.
Read more here http://msdn.microsoft.com/en-us/library/4hx47hfe.aspx#remarksToggle
I have a Listview and one of the columns is called id_Number.
Is it possible to redirect to another page, if user clicks on one of the rows?
For example if id_Number is 4, than page should be redirected to ~/Page.aspx?id=4.
Code:
<asp:ListView ID="ListView1" runat="server"
DataKeyNames="id_Number" >
<EmptyDataTemplate>
<table id="Table1" runat="server" style="">
<tr>
<td>
No data was returned.</td>
</tr>
</table>
</EmptyDataTemplate>
<ItemTemplate>
<tr style="font-family: Arial; color: #FFFFFF" onMouseOver="this.bgColor='#219DD0';" onMouseOut="this.bgColor='#252526';">
<td>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("id_Number") %>' />
</td>
<td>
<asp:Label ID="TextLabel" runat="server" Text='<%# Eval("Text") %>' />
</td>
<td>
<asp:Label ID="DateLabel" runat="server" Text='<%# Eval("Date") %>' />
</td>
</tr>
</ItemTemplate>
<LayoutTemplate>
<table id="Table2" runat="server">
<tr id="Tr1" runat="server">
<td id="Td1" runat="server">
<table ID="itemPlaceholderContainer" runat="server" border="0" style="">
<tr id="Tr2" runat="server" style="">
<th id="Th1" runat="server">
Name</th>
<th id="Th2" runat="server">
Text</th>
<th id="Th3" runat="server">
Date</th>
</tr>
<tr ID="itemPlaceholder" runat="server">
</tr>
</table>
</td>
</tr>
</table>
</LayoutTemplate>
</asp:ListView>
You can add an HTML link or a JavaScript into the ItemTemplate of your ListView pretty easily:
The "columns" are just HTML columns; in the ItemTemplate, you have access to all of your data, including id_number, so you can use it anywhere in the HTML, not just inside a column.
Since you wan the whole row to be clickable, I'd use a JavaScript function on the onClick event of the HTML table row <TR> element. You already have 2 events (onMouseOver, onMouseOut), with JavaScript in them, so this would just be one more...
A JavaScript redirect utilizes window.location.href which will redirect in the same window, assuming that's what you want (as opposed to a new window, etc.):
<ItemTemplate>
<tr style="font-family: Arial; color: #FFFFFF"
onMouseOver="this.bgColor='#219DD0';"
onMouseOut="this.bgColor='#252526';"
onClick="window.location.href = 'some/path/Page.aspx?id=<%# Eval("id_Number") %>';"
<td>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("id_Number") %>' />
</td>
<td>
<asp:Label ID="TextLabel" runat="server" Text='<%# Eval("Text") %>' />
</td>
<td>
<asp:Label ID="DateLabel" runat="server" Text='<%# Eval("Date") %>' />
</td>
</tr>
</ItemTemplate>
One thing to note is for the path of Page.aspx, you have to use a relative path.
~/page.aspx?id=
Is a .net path that gets compiled into the full relative path to that page.
However, bacause your ItemTemplate contains HTML, you'd need the full (relative) path to Page.aspx in there.
So instead it should be (just an example):
/some/path/page.aspx?id= <-- page.aspx lives on http://www.yoursite.com/some/path/page.aspx
/page.aspx?id= <-- page.aspx lives on root, http://www.yoursite.com/page.aspx
Alternately you can use
onClick="window.location.href = '<% System.Web.VirtualPathUtility.ToAbsolute("~/Page.Aspx?ID=" + Eval("id_number")); %>';"
Ok so I have an update panel sorrounding my controls. I have 2 dropdownlists which have functions they run from codebehind and a repeater of items. I've done the test in a Repeater using a button it doesn't do a postback, but the linkbutton does. What am I doing wrong?
also this is inside a usercontrol no aspx page.
<asp:UpdatePanel ID="upLocation" runat="server" UpdateMode="Conditional" RenderMode="Inline">
<ContentTemplate>
<asp:Repeater ID="rptMuniProducts" runat="server">
<HeaderTemplate>
<table class="table">
<thead>
<tr>
<th class="w80"></th>
<th>Product</th>
<th>Product Type</th>
</tr>
</thead>
<tbody>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td class="actions">
<asp:Button ID="btnProd" runat="server" OnClick="btnProd_Click" Text="test" />
<asp:LinkButton ID="lnkDeleteProd" runat="server" OnClick="lnkDeleteProd_Click">Link Test</asp:LinkButton>
<asp:HiddenField ID="hdnId" runat="server" Value='<%# DataBinder.Eval(Container, "DataItem.Id") %>' />
</td>
<td><%# DataBinder.Eval(Container, "DataItem.Name") %></td>
<td><%# DataBinder.Eval(Container, "DataItem.Producttype") %></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</tbody>
</table>
</FooterTemplate>
</asp:Repeater>
</ContentTemplate>
</asp:UpdatePanel>
Have you tried setting ClientIDMode=Auto on the LinkButton? There's a long-standing .NET bug with doPostBack and non-auto client ids.
I have a problem getting an <asp:UpdatePanel..> to work inside a <table>.. <tr> </tr> structure and I don't know why. When the UpdatePanel is commented out everything works fine, but when I un-comment the UpdatePanel the contents of the <tr> </tr> tag doesn't even show up in Visual Studio 2010. This content does display when I run the web page but the UpdatePanel doesn't work. Non of my other web pages in this project have this problem but, then again, I use <div>s instead of <table>s in them.
One other thing. The is in my MasterPage.
Here is my script:
<asp:UpdatePanel ID="W9UpdatePanel" runat="server" UpdateMode="Always">
<ContentTemplate>
<tr>
<td colspan="6">
<div class="branchSetupSectionTitle">W-9 Information:</div>
</td>
</tr>
<tr>
<td colspan="2">
<asp:Button ID="btnDownloadW9Pdf" runat="server"
Text="Download W-9" onclick="btnDownloadW9Pdf_Click" AutoPostBack="True" />
<%--<asp:RegularExpressionValidator ID="RegularExpressionValidator24"
runat="server" ControlToValidate="txtFirstPaymentAmount" Display="Dynamic"
ErrorMessage="The dollar amount you entered is in the wrong format."
ForeColor="Red" ValidationExpression="^\d+(\.\d\d)?$">*</asp:RegularExpressionValidator>--%>
<asp:CheckBox ID="chkW9FormSubmitted" runat="server" AutoPostBack="True"
oncheckedchanged="chkW9FormSubmitted_CheckedChanged"
Text=" I have submitted this W-9 Form" />
</td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</ContentTemplate>
</asp:UpdatePanel>
</tr>
The event fires for both the button and the checkbox but the entire page is refreshed.
Thanks for your help.
UpdatePanel needs to render a div or span in order to function correctly. Since neither of these elements can be rendered between table rows, UpdatePanel does not have a placeholder to render the postback response html, and thus it doesn't work.
A workaround in your case may be to see which part of your page does not need to be inside the update panel and leave it outside. You could leave just the contents of <td colspan="2"> inside the UpdatePanel.
<asp:ScriptManager ID="scm" runat="server">
</asp:ScriptManager>
<fieldset>
<legend>Truck Master Entry Form</legend>
<asp:UpdatePanel ID="upd1" runat="server">
<ContentTemplate>
<table cellpadding="2" cellspacing="1">
<tr>
<td align="right">
Truck no :
</td>
<td align="left">
<asp:TextBox ID="truckno" runat="server" Width="120px" Height="20px" />
</td>
</tr>
<tr>
<td align="right">
Size :
</td>
<td align="left">
<asp:DropDownList ID="drptrucksize" runat="server" Width="120px" Height="20px" DataValueField="WEIGHT"
DataTextField="SIZE" OnSelectedIndexChanged="drptrucksize_SelectedIndexChanged"
AutoPostBack="true" />
</td>
</tr>
<tr>
<td align="right">
Type :
</td>
<td align="left">
<asp:TextBox ID="txttrucktype" runat="server" Width="120px" Height="20px" />
</td>
</tr>
<tr>
<td align="right">
Weight :
</td>
<td align="left">
<asp:TextBox ID="txtweight" runat="server" Width="120px" Height="20px" />
</td>
</tr>
<tr>
<td align="right">
</td>
<td align="left">
<asp:Button ID="btnsave" runat="server" Text="Save" Width="100px" Height="50px" />
<asp:Button ID="btncancel" runat="server" Text="Cancel" Width="100px" Height="50px" />
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
The update panel need to be put outside the table. Look at
Mohammad Shahnawaz's code.
I installed the Asp.net Ajax toolkit. In my site I use the NummericUpDown from that toolkit.
Now, I want that a label changes when the NummericUpDown Textboxes changes. I try to use JavaScript for this, but I always get the following error:
'ASP.orders_aspx' does not contain a definition for 'changeAmount' and no extension method 'changeAmount' accepting a first argument of type 'ASP.orders_aspx' could be found (are you missing a using directive or an assembly reference?)
This is my code:
<%# Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true"
CodeFile="orders.aspx.cs" Inherits="orders" Title="the BookStore" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
<script type="text/javascript">
function changeAmount()
{
var amount = document.getElementById("txtCount");
var total = 10 * amount.value;
document.getElementById("lblPrice").value = total;
}
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<ajaxToolkit:ToolkitScriptManager runat="Server" EnablePartialRendering="true" ID="ScriptManager1" />
<h1 id="H1" runat="server">
Bestellen</h1>
<asp:Panel ID="pnlZoeken" runat="server" Visible="true">
<asp:ObjectDataSource ID="objdsSelectedBooks" runat="server" OnSelecting="objdsSelectedBooks_Selecting"
TypeName="DAL.BooksDAL"></asp:ObjectDataSource>
<h3>
Overzicht van het gekozen boek</h3>
<asp:FormView ID="fvBestelBoek" runat="server" Width="650">
<ItemTemplate>
<h3>
Aantal boeken bestellen</h3>
<table width="650">
<tr class="txtBox">
<td>
Boek
</td>
<td>
Prijs
</td>
<td>
Aantal
</td>
<td>
Korting
</td>
<td>
Totale Prijs
</td>
</tr>
<tr>
<td>
<%# Eval("TITLE") %>
</td>
<td>
<asp:Label ID="lblPrice" runat="server" Text='<%# Eval("PRICE") %>' />
</td>
<td>
<asp:TextBox OnTextChanged="changeAmount()" ID="txtCount" runat="server"></asp:TextBox>
<ajaxToolkit:NumericUpDownExtender ID="NumericUpDownExtender1" runat="server" TargetControlID="txtCount"
Width="50" Minimum="1" ServiceDownMethod="" ServiceUpMethod="" />
</td>
<td>
-
</td>
<td>
<asp:Label ID="lblAmount" runat="server" />
</td>
</tr>
</table>
</ItemTemplate>
</asp:FormView>
<asp:Button ID="btnBestel" runat="server" CssClass="btn" Text="Bestel" OnClick="btnBestel_Click1" />
<asp:Button ID="btnReChoose" runat="server" CssClass="btnDelete" Text="Kies een ander boek"
OnClick="btnRechoose_Click" />
</asp:Panel>
</asp:Content>
Does anyone know the answer?
Thanks a lot, Vincent
You're trying to assign a client-side method to the OnTextChanged event, which is a server-side event.
Also, your javascript is referencing the server id of the label and textbox. The WinForms engine appends characters to this depending where the control is nested. Use <%=myControl.ClientID%> to get around this.
You need to use some pure Javascript for this:
window.onload=function(){
//assign client method to textbox
document.getElementById('<%=txtCount.ClientID%>').onChange = function(){
var amount = document.getElementById('<%=txtCount.ClientID%>');
var total = 10 * amount.value;
document.getElementById('<%=lblPrice.ClientID%>').value = total;
}
}
Place that on your page instead of your current Javascript and get rid of the OnTextChanged="changeAmount()" attribute.
You set OnTextChanged for TextBox. It is refer to server method, that is fired on PostBack.
If you want to handle Up and Down events in background by method on your Page, you have to set
properties ServiceUpPath and ServiceUpMethod for NumericUpDown tag.
If you want to handle client events - set custom Up and Down buttons and set property OnClientClick to them.
See
http://www.asp.net/AJAX/AjaxControlToolkit/Samples/NumericUpDown/NumericUpDown.aspx