How To Use The Name Of The Property That Rendering Inside Template
Apr 29, 2010
I'm reviewing new features of ASP.NET MVC 2.0. During the review i found really interesting using Templated Helpers. As they described it, the primary reason of using them is to provide common way of how some datatypes should be rendered. Now i want to use this way in my project for DateTime datatype My project was written for the MVC 1.0 so generating of editbox is looking like this:
<%= Html.TextBox("BirthDate", Model.BirthDate, new { maxlength = 10, size = 10, @class = "BirthDate-date" })%>
<script type="text/javascript">
$(document).ready(function() {
$(".BirthDate-date").datepicker({ showOn: 'button', buttonImage: '<%=Url.Content("~/images/i_calendar.gif") %>', buttonImageOnly: true });
});
</script>
Now i want to use Template Helper, so i want to have above code once i type next sentence:
<%=Html.EditorFor(f=>f.BirthDate) %>
According to the manual I create DataTime.ascx partial view inside Shared/EditorTemplates folder. I put there above code and stacked with the problem. How can i pass the name of the property that I'm rendering with template helper? As you can see from my example, i really need it, since I'm using the name of the property to specify data value and parameter name that will be send during the POST requsest. Also, I'm using it to generate class name for JS calendar building. I tried to remove my partial class for template helper and made MVC to generate its default behavior. Here what it generated for me:
<input type="text" value="04/29/2010" name="LoanApplicationDays" id="LoanApplicationDays" class="text-box single-line">
As you can see, it used the name of the property for "name" and "id" attributes. This example let me to presume that Template Helper knows about the name of the property. So, there should be some way of how to use it in custom implementation.
View 1 Replies
Similar Messages:
Feb 18, 2011
I need to Bind "JobRefNo" to the query string.Below binding gives an error.what is the correct way?
<asp:LinkButton ID="MoreLinkButton" PostBackUrl="/real/Coordinator/Home.aspx?JobRefNo="'<%# Bind("JobRefNo") %>' runat="server">Go To Job...</asp:LinkButton>
Link Button is inside a DataList control.Error says "Call to Bind must be assigned to a property of a control inside a template"
View 1 Replies
Aug 29, 2010
I have ASPxDataView and ASPxRadioButtonList within item template. i also have two SQLDataSource's (first fill ASPxDataView, second ASPxRadioButtonList). They are using other database tables connected with the foreign key. Is there any way to pass parameter to my second sqlDataSource (id) to fill RadioButtonList property ? i mean select * from TABLE2 where id = @id ; (@id is a value from TABLE1 which is a value of column returned by first sqlDataSource)
View 3 Replies
Feb 12, 2010
I'm trying to write a custom rendering template for use in the DisplayForm of a list whose fields include Title, HeaderImageUrl, Body. I've got the following so far:
<SharePoint:RenderingTemplate ID="NewsListForm" runat="server">
<Template>
<h1><SharePoint:FieldValue FieldName="Title" runat="server"/></h1>
<div>
<p>
<SharePoint:UrlField FieldName="HeaderImageUrl" runat="server"></SharePoint:UrlField>
<SharePoint:RichTextField FieldName="Body" runat="server" />
</p>
</div>
</Template>
</SharePoint:RenderingTemplate>
The HeaderImageUrl field is configured to be an Image URL, but when I use the UrlField control, it renders a link.
I was thinking there might be a way to grab field values and put them in attributes, so something like this:
<asp:Image ImageUrl="<% FieldValue["HeaderImageUrl"] %>" runat="server"/>
If this kind of thing isn't possible, then is there another control in Microsoft.SharePoint.WebControls that would render an image from a URL?
View 4 Replies
Nov 22, 2010
I'm working on a custom navigation menu, I've added the following property within my MenuItem class to allow users add them controls into it.
View 1 Replies
Jan 7, 2010
I have Two Datalist Control . One is dtlistCat and second is dtlistSeries. dtlistSeries is filled by dtlistCat by dtlistCat_ItemDataBound method .
Coding side is ok . But Only problem in rendering . I want the page render with dtlistSeries has 2 repeat column in verticle direction I think only designning part creating problem .Not proper width or height specified so.
ViewSeries.aspx
<%@ Page Language="C#" MasterPageFile="~/MasterPage/Store.master" AutoEventWireup="true"
View 2 Replies
Jan 13, 2010
my problem as follow:
1-i have UpdatePanel contain Gridview
2- i have Ajax Control ToolKit HTML Editor OutSide My UpdatePanel and its not inside any control.
my problem when make HTMLedior (visible=false ) onpage event, MyupdatePanel Render Control Much Fast, but when i Make it visible its slow my application althougth this htmleditor not included in any update panel and its not refreshed.
View 8 Replies
Oct 7, 2010
i have a repeator control that is bind to a dataset, one of the field is image path that is bind with <img src tag. Now the problem is so of the articles are with out any image, how can i make sure that <img tag only render when there is an image name exist?
[Code]....
View 4 Replies
Mar 6, 2011
1: I have a .html file that has some markup with some placeholder tags.
[code]...
4: PersonInfo.aspx is literally empty since I am injecting html from code-behind.
When the PersonInfo.aspx is called the html-template markup with appropriate values in the placeholder will be displayed. Also there are chances I would like to send the final markup in an html email (though that is not part of the question as I know how to email).
Is this the best way to fill values in my html-template or is the any other better alternative?
Note: This is a very simple sample example. My class is very complex involving objects as properties and also my html template have 40-50 placeholders.
So code in my step 3 will need 40-50 Replace statements.
View 3 Replies
Mar 15, 2011
I need to get access to the page index of the gridview so I can correctly get some data from a coresponding array to set the cell's contol properties correctly. Below is what I've got so far. The ExcelObject is a class that houses both the data read in from an sutomer submitted excel file and a matching 2 dimensional array of characteristics that I use in this case to set the CssClass property. My problem is that when I enable paging for the gridview I don't get the proper datasource row index when the data is read by the databinder.eval; what I'm getting is the current row of the gridview being generated.
[Code]....
View 2 Replies
Apr 27, 2010
Here is a perplexing issue I have not seen a good answer to on StackOverflow, although there a couple stabs at it... I have a situation where I'd like to do this:
<asp:Repeater ID="MyRepeater" runat="server" OnItemDataBound="MyRepeater_ItemDataBound">
<ItemTemplate>
<li id="id?">
All the other stuff
</li>
</ItemTemplate>
</asp:Repeater>
is how do I get the ID of my <li> elements to be id1, id2, id3, etc., based on the ItemIndex they are bound to? So far the most... er..."elegant" solution I've come up with is to replace the <li> with an asp:Literal and dump the <li...>' text. But that just feels... so wrong. And no, I'm not using ASP.NET 4.0, which I've read will provide this functionality.
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
Jul 22, 2010
NavigateUrl='<%#"ReportViewer.aspx?id1="+Eval("ID1")+"&id2="Eval("ID2") %>'
this is inside a Gridview template. There is some error with this.
View 7 Replies
Jan 7, 2010
I'm using a FormView with a dynamically loaded item template. Inside the template (an ascx file loaded through Page.LoadTemplate(...) ) there is a button and I need to invoke the click event on that button.
View 1 Replies
Jan 6, 2010
I am trying to access a LinkButton that is inside a PagerTemplate in a GridView.
However, I am getting a NullReferenceException and I don't know what I am doing wrong here.
I have tried the following...
((LinkButton)GridView1.BottomPagerRow.FindControl("lnkbtnPrevious"));
((LinkButton)GridView1.FindControl("lnkbtnPrevious"));
View 3 Replies
Oct 27, 2010
How do I access a specific control within a FormView's "<InsertItemTemplate>"?
View 2 Replies
Oct 16, 2010
referencing a control inside the createuserWizard template of the createuserStep
I tried like this:
Dim lastn As TextBox = CType(CreateUserWizard1.FindControl("LastNameTxt"), TextBox)
and like that:
[code]....
View 1 Replies
May 6, 2015
I have a gridview that I want to show a dropdownlist (for, let's say, column1) when it has a certain value, and I want to change that same column into a label when it has a certain value. Is this possible with gridview? if so, how?
View 2 Replies
Aug 3, 2012
I tried to get the LoginName control inside LoginView LoggedIn template , despite several methods, the code still could not work.
I wished to change the default username to the customer name.
Here is the code:
<asp:LoginView ID="LoginView1" runat="server">
<LoggedInTemplate>
Hello, <asp:LoginName ID="LoginName1" runat="server"></asp:LoginName>
<br />
<div style="text-align: right; margin-right: 5px ">
<asp:LoginStatus ID="LoginStatus1" runat="server" LogoutPageUrl="~/Home.aspx" Font-Underline="True" />
</div></div>
</LoggedInTemplate>
</asp:LoginView>
At the code behind :
protected void Login1_LoggedIn(object sender, EventArgs e) {
LoginName loginName = LoginView1.FindControl("LoginName1") as LoginName;
Response.Write(loginName.ToString()); //for now I used Response.Write for testing purposes
}
View 1 Replies
Dec 22, 2010
I want to disallow entering html tags inside specific textFields using custom attribute HtmlRemove, but I don't know how can I acces property/Field value? Model:
[Code]....
My custom Attribute
[Code]....
View 8 Replies
Oct 8, 2010
I am trying to have different options for different user roles. Here is my code:
[code]....
View 2 Replies
Nov 29, 2010
I added a (Read More...) Div to my repeater's item template, that doesn't contain any information.
I want to add a text button or an anchor to my item template..when it's clicked it should call a javascript method that writes information to the Div and it will take the content to write as a parameter, the content will be passed as an Eval method, for example it will eval("education")...and when it's clicked again it will hide the Div
I tried various and near approaches but it all worked outside the repeater and item template tags, but if I placed the identical code to the repeater and my javascript to the head tag it won't function!
I don't want to post my code, because I'm sure it's an easy and essential trick for any developer...so I was hoping for an original example not an edit to my test code(beginners logic)
View 1 Replies
Sep 13, 2010
I am trying to change the textboxes in the FormView insert template to dropdownlists but they keep setting the parameters to null. Here's what I have:
[Code]....
In Page_Load
CType(frmSurvey.FindControl("ddlYearOfQualification"), DropDownList).Items.Add(New ListItem("2010", "2010"))
CType(frmSurvey.FindControl("ddlYearOfQualification"), DropDownList).Items.Add(New ListItem("2009", "2009"))
and in the SqlDataSource
InsertCommand="INSERT INTO [tblSurvey] (... [YearOfQualification] ...) VALUES ( ... @YearOfQualification ... )
And in insert parameters:
<asp:Parameter Name="YearOfQualification" Type="Int16" />
And the insert fails with YearOfQualification as null. If I sue the standard textbox:
<asp:TextBox ID="YearOfQualificationTextBox" runat="server"
Text='<%# Bind("YearOfQualification") %>' />
View 2 Replies
Jan 6, 2010
I keep getting a null reference when I try to access a listbox inside the EditItemTemplate of a formview. I check the mode before accessing the control (Formview1.CurrentMode) to make sure it is in edit mode and even set it manually to edit mode again! But formview1.findcontrol("blah") returns null. Formview1.EditItemTemplate does not have a FindControl method, not sure what else to try.
View 1 Replies
Aug 20, 2010
In my listview object insert/edit template, I have two dropdownlists (category, subcategory). When a user selects a category (autopostback), I would like the subcategory dropdown to filter to only the those that match the categoryID from the category ddl. This seems to be complicated by the fact that it is in a listview object. I'm currently using a queryextender on the subcategory datasource, but I'm not sure how to apply the selectedvalue of the category to the queryextender. The subcategory just shows all items and is not filtered. How do you accomplish this?
View 1 Replies