I have a table of roles that has checkboxes with access or not. I need a help-button on the right most column that shows information for the role using JQuery Dialog. For some reason the dialog only shows every second time.
Below is the code I use:
<table width="100%" border="0" cellspacing="0" cellpadding="5">
<%foreach (Role role in ViewData["Roles"] as List<Role>)
{ %>
<tr>
<td width="20%">
<%=role.RoleName %>
</td>
<td width="70%">
<%=Html.CheckBox(role.RoleName, Model.IsInRole(role.LoweredRoleName)) %>
</td>
<td width="10%">
<%if (!string.IsNullOrEmpty(role.Description))
{ %>
<%Html.RenderPartial("Help", new KeyValuePair<string, string>(role.RoleName, role.Description)); %>
<%} %>
</td>
</tr>
<%} %>
</table>
Help.aspx:
<%# Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<KeyValuePair<string, string>>" %>
<a href="#" onclick="$('#<%=Model.Key.Replace(" ", "") %>').dialog(); return false;">
<img border="0" src="../../Content/Images/help_icon.gif" alt="?"/>
</a>
<div id="<%=Model.Key.Replace(" ", "") %>" title="<%=Model.Key %>" style="display:none;">
<%=Model.Value %>
</div>
A call to $(foo).dialog() will initialize a dialog instance and will auto-open the dialog by default. If you want to reuse a dialog, the easiest way is to disable the "auto-open" option with: $(foo).dialog({ autoOpen: false }) and open it with $(foo).dialog('open')
http://docs.jquery.com/UI/Dialog#overview and
http://blog.nemikor.com/2009/04/08/basic-usage-of-the-jquery-ui-dialog/
But I'd suggest to use something like http://plugins.learningjquery.com/cluetip/ instead. ClueTip has options to be opened via click and stay until closed, so you can choose between hover and click activation. It is also extremely easy to get content via AJAX, so you don't have to load page full of information that user may never click to see.
Related
I have been attempting this all morning with no results. I can't seem to figure out what I'm doing wrong. I have checked out the two links (among many other unhelpful links) and have yet to solve my issue. This is a WebUserControl...
Receiving the following error:
Control 'HeadContent_CareersViewPosting_txtFirstName' of type
'TextBox' must be placed inside a form tag with runat=server.
Already attempted the suggestions here, here and here and no results. Still received the exact same message. Some new suggestions would be greatly appreciated!
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="Careers View Posting.ascx.cs" Inherits="ascxStagingApplication.Careers.Careers_View_Posting" %>
<asp:Panel ID="pnlResume" runat="server">
<table ID="tblMain" runat="server">
<tr>
<td>
<asp:Label ID="lblFirstName" runat="server" Text="* First Name"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtFirstName" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblLastName" runat="server" Text="* Last Name"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtLastName" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblEmail" runat="server" Text="* Email"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtEmail" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblResume" runat="server" Text="* Resume"></asp:Label>
</td>
<td>
<asp:FileUpload ID="fupResume" runat="server" />
</td>
</tr>
<tr>
<td>
<asp:Button ID="btnSubmit" runat="server" Text="Submit"/>
</td>
</tr>
</table>
</asp:Panel>
The user control is currently being placed onto a dummy webpage for testing. Here is the 'dummy' page code.
<%# Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Page Careers View Posting.aspx.cs" Inherits="ascxStagingApplication.Careers.Page_Careers_View_Posting" %>
<%# Register Src="~/Careers/Careers View Posting.ascx" TagPrefix="uc1" TagName="CareersViewPosting" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
<uc1:CareersViewPosting runat="server" id="CareersViewPosting" />
</asp:Content>
In ASPNet webforms - everything needs to run within a form tag.
All server controls must appear within a <form> tag, and the <form> tag must contain the runat="server" attribute. The runat="server" attribute indicates that the form should be processed on the server. It also indicates that the enclosed controls can be accessed by server scripts:
<form runat="server">
...HTML + server controls
</form>
In your dummy page try the following to allow the server controls to run.
<%# Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Page Careers View Posting.aspx.cs" Inherits="ascxStagingApplication.Careers.Page_Careers_View_Posting" %>
<%# Register Src="~/Careers/Careers View Posting.ascx" TagPrefix="uc1" TagName="CareersViewPosting" %>
<form runat="server">
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
<uc1:CareersViewPosting runat="server" id="CareersViewPosting" />
</asp:Content>
</form>
Also - check that your ~/Site.Master file contains the <form runat="server"> if not -a s it would be fairly typical for that to be the place to have your all enclosing form tag.
You could read more here: http://www.w3schools.com/aspnet/aspnet_forms.asp
If you put right of runat="server" but still error, please try this code.
public override void VerifyRenderingInServerForm(Control control)
{
/* Confirms that an HtmlForm control is rendered for the specified ASP.NET
server control at run time. */
}
cr. from Rohit Rao
sorry for my bad skill English.
All server controls must appear within a <form> tag, and the <form> tag must contain the runat="server" attribute.
All the Asp.net controls are server controls,so these should be placed within form tag with runat="server" attribute, like this
<form runat="server">
place server controls here...
</form>
>Button bt = new Button();
>bt.ID = "dd";
>bt.Text = "Click Me";
>this.Form.Controls.Add(bt);
you can add
<form runnat="server">
// add content placeholder
</form>
If I want to combine asp.net code with html (mark up) file, I need to open <% %> and execute teh code.
What If I want to iterate over a database with select query while feeding information and creating rows. For example:
<table>
<%
foreach(DataRow dr in dataset.Tables["empoloyees"].Rows)
{
%>
<tr>
<td>
<asp:Label runat="Server" Text="<% dr[FirstName].toString(); %>"/>
</td>
<td>
<asp:Label runat="Server" Text="<%dr[LastName].toString();%>"/>
</td>
</tr>
<%
}
%>
</table>
Is the syntax correct..and is that practice good (it is always used in php) ? or should I bind the data to the label somehow?(no idea how. but somehow)?
If you're trying to take a set of data and display it in a table then try using control like the GridView or the Repeater.
First and most important thing - do not mix business logic and data access functionality with the data representation markup!
Supposing you are using WebForms, you can use Repeater control which is bound in the code behind of a page/control (aspx.cs/ascx.cs) so View stay decoupled and just bound to specific properties of data source:
ASPX:
<asp:Repeater ID="employees" runat="server">
<HeaderTemplate>
<table>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<asp:Label runat="Server"
Text="<%# DataBinder.Eval(Container.DataItem, "FirstName") %>"/>
</td>
<td>
<asp:Label runat="Server"
Text="<%# DataBinder.Eval(Container.DataItem, "LastName") %>"/>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
Code Behind: (Page_Load() for instance)
employees.DataSource = dataset.Tables["empoloyees"].Rows;
employees.DataBind();
I suggest using a Repeater control if you want a piece of markup to iterate over and bind to it.
<asp:Repeater id="Repeater1" runat="server">
<ItemTemplate>
<tr>
<td> <%# DataBinder.Eval(Container.DataItem, "FirstName") %> </td>
<td> <%# DataBinder.Eval(Container.DataItem, "LastName") %> </td>
</tr>
</ItemTemplate>
</asp:Repeater>
Alternatively, use a GridView, though I find that Repeater gives you more control over the emitted markup.
You are almost there. Try this:
<table>
<%
foreach(DataRow dr in dataset.Tables["empoloyees"].Rows)
{
%>
<tr>
<td>
<%= dr[FirstName].toString(); %>
</td>
<td>
<%= dr[LastName].toString();%>
</td>
</tr>
<%
}
%>
</table>
You should use a repeater instead something like this
<table>
<asp:Repeater runat="server" ID="userRepeater" >
<ItemTemplate>
<tr>
<td><%#DataBinder.Eval(Container.DataItem,"FirstName")%></td>
<td><%#DataBinder.Eval(Container.DataItem,"LastName")%></td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>
and in your codebehind
userRepeater.DataSource = dataset.Tables["empoloyees"];
userRepeater.DataBind();
for a list of all types of <% %> take a look here
You don't have to use <% %> at all. Just put your code in between tags with runat="server", and then go ahead and use standard ASP.NET tags (e.g. asp:TextBox runat="server"). Just make sure it's an *.aspx page.
FWIW, your question seems a little backwards to me. If you are creating *.aspx pages then you can just use standard HTML anywhere you want. If you are trying to somehow squish ASP.NET into an *.html page - then you are misunderstanding how ASP.NET works.
I Add DateTime Datetime.ascx
\Views\Shared\EditorTemplates\
<%# Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<System.DateTime>" %>
<%= Html.TextBox("", String.Format("{0:yyyy-MM-dd HH:mm}",Model)) %>
<script type="text/javascript">
$(function () {
$('#EventDate').datetime({
userLang: 'en',
americanMode: true
});
});
</script>
And I Need to Use it in my DateFrom - To Texbox.
<%# Register src="../Shared/EditorTemplates/DateTime.ascx" tagname="DateTime" tagprefix="uc1" %>
<p>
Please enter your Date Range Below.
</p>
<p>
Please enter your Date Range Below.
</p>
<form method="post" action="<%= Html.AttributeEncode(Url.Action("List")) %>">
<div>
<table cellpadding="2" cellspacing="0" class="vertical">
<tr>
<th>Date From:</th>
<td><%= Html.TextBox("datefrom") %></td>
</tr>
<tr>
<th>Date To:</th>
<td><%= Html.TextBox("dateto")%></td>
</tr>
<tr>
<th></th>
<td><input type="submit" value="Show My Orders" /></td>
</tr>
</table>
</div>
</form>
I got the Datetime.ascx from Nerdinner
Thanks in Regards
You need to use the Html.EditorFor instead of Html.TextBox
BTW, can you even use the <%# register ..%> syntax in MVC? I've only ever used it in ASP.NET WebForms (although, I'm only using Razor now so my ASCX is kind of rusty)
I have a listview control on an .aspx page. Inside this list view i want to check "Type" property which comes from database. here is the example code :
<ItemTemplate>
<%# if(Convert.ToInt32(DataBinder.Eval(Container.DataItem,"Type")) == 0){ %>
<tr class="item">
<td>
<%# Convert.ToDateTime(Eval("WorkDate")).ToShortDateString() %>
</td>
<td style="text-align: center;">
<%# Eval("SkillName") %>
</td>
</tr>
<%# } else if (Convert.ToInt32(DataBinder.Eval(Container.DataItem,"Type")) == 1) {%>
<tr class="item">
<td colspan="2">
<strong><%# Convert.ToDateTime(Eval("WorkDate")).ToShortDateString() %></strong>
</td>
</tr>
<% } %>
</ItemTemplate>
As a last resort i tried to user DataBinder.Eval() but i get the exception "Expected class, delegate, enum, interface, or struct". What can i be doing wrong? Writing a function in code-behind isn't an option for me. Is there a way to achieve this?
Here is the full code, made fancy and short.
<ItemTemplate>
<tr class="item">
<td colspan="<%# Eval(Container.DataItem,"Type")) == 0 ? 1:2%>">
<strong><%# Convert.ToDateTime(Eval("WorkDate")).ToShortDateString() %></strong>
</td>
<td style="text-align: center;" visible="<%# Eval(Container.DataItem,"Type")) == 1>">
<%# Eval("SkillName") %>
</td>
</tr>
</ItemTemplate>
Untested, as I don't have Visual Studio available at the moment, but since HtmlTableRow has a Visible property, the following should work:
<tr class="item" runat="server" Visible='<%# Convert.ToInt32(Eval("Type")) == 0 %>'>
...
</tr>
yes you will have to do some client side scripting though... I would suggest jquery..
you would basically loop through all of the rows in jquery and based on the data in the row you would be able to change the innerhtml of the row object based on the ".item" selector to determine whether it should be in one format or the other.
I have a simple form. Its got one field and a submit button.
I hide the submit button. The submit button is actually triggered with an anchor
tag that calls a javascript method that uses jQuery to get the element and execute
a click(). This works fine, the form posts and record is successfully written into the DB.
So now I added xVal for validation. I am trying to add in the simple client side validation.
It doesn't work when I click the anchor tag. However, if I un-hide the submit button and try posting the form with that instead of using the anchor tag that's calls the js method, it does work. So basically I am trying to figure out why it doesn't work when I use the js method to trigger the click of the submit button.
Any grande ideas? Thanks much!
Heres some code...
<div id="manufacturerButtons" class="moduleRow">
<%= Html.ActionImage(Url.Content("~/Content/Icons/bullet_go_back.png"), "Back To Admin", "Admin", "Admin")%>
| <a class="actionImage" href="javascript: addManufacturer();">
<img border="0" src="<%= Url.Content("~/Content/Icons/accept.png")%>"> <span>Add
Manufacturer </span></a>
</div>
<div class="moduleContent">
<div id="manufacturerContainer">
<div class="moduleRow">
<h3>
New Manufacturer</h3>
</div>
<div class="moduleRow">
<% Html.BeginForm("NewManufacturer", "Admin", FormMethod.Post); %>
<table class="noBorder" border="0" cellpadding="0" cellspacing="0">
<tr>
<td style="width: 125px">
<h6>Name:</h6>
</td>
<td>
<%= Html.TextBox("Name") %>
</td>
</tr>
<tr style="display: none;">
<td>
</td>
<td>
<input type="submit" id="btnAdd" name="btnAdd" />
</td>
</tr>
</table>
<% Html.EndForm(); %>
<%= Html.ClientSideValidation<EquipmentManufacturer>() %>
</div>
</div>
Javascript:
function addManufacturer() {
//$('form').submit(); // doesnt work when trying to validate either
$('#btnAdd').click();
return true;
}
What you need to do is trigger the jQuery validation on your form. Try:
$('form').validate();
To submit the form upon successful validation, try:
$('form').validate({ submitHandler: function(form) { form.submit(); } });
Note that 'form' should be a valid jQuery selector for your form...