Rendering Server Tags At Runtime?
Feb 28, 2010Is it possible that I reserve a asp.net code in db and load it at runtime. the asp.net code contains server side tags like Text='<%# Eval("Description") %>'
View 1 RepliesIs it possible that I reserve a asp.net code in db and load it at runtime. the asp.net code contains server side tags like Text='<%# Eval("Description") %>'
View 1 RepliesI'm using a jQuery modal form to gather some information about a user and then redirecting them to another view. However, my submit button will not fire because none of the content is rendering inside the form tags on the generated output.
Here is my code:
[Code]....
[Code]....
[Code]....
I have created a Default.aspx page using HTML5 tags such as header, nav, section, footer.
1. The content renders fine on my dev machine (running IE11).
2. However, it doesn't render on my network (live client) PC running IE11. But, it is fine rendering in Chrome!!!!
Here is an example:
Code:
<body>
<form id="frmDefault" runat="server">
<header>
<h1>Resource Portal</h1>
</header>
<nav>
<ajaxToolkit:ToolkitScriptManager ID="ToolkitScriptManager" runat="server" />
[Code] ....
I am having an issue with the gridview in ASP.NET. Everything works well when running from IDE in both debug and without debug. When I publish to IIS I have a gridview that I use in two places. It works fine in one place but not the other. In one instance I am using an IFRAME tag to display the page that uses this data grid. When I first load it it works fine, I can click on a row. But after clicking on that row after the first postback, I can no longer get it to postback again on future clicks. I used firefly and after clicking the first time on the grid, the tags for the table are not rendered though I can clearly see the grid. Confused... Here is the rendered code before clicking on it using firefly. (oh yea, this gridview is also inside of an updatePanel) (In the below I replaced actual data with xxxx)
[Code]....
Below is the code after clicking on the grid.
<div id="UpdatePanel1">
<div style="background-color: white; width: 818px; height: 405px; overflow: auto" onscroll="GetScroll()" id="divFill">
<div style="padding-bottom: 5px; background-color: buttonface; width: 818px; height: 20px; padding-top: 5px" id="NavFoot" align="right">
</div>
Also, if I did not provide enough information let me know.
I am binding the textbox backcolor from database. My code is looking like this
<asp:TextBox ID="TextBox1" runat="server" BackColor='<%#(Eval("Colour")) %>' Enabled="False" Width="18px" BorderWidth="0px"></asp:TextBox>
When i execute this page i am getting the following error.
Specified cast is not valid. Description: An unhandled exception occurred during the execution of the current web request. review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidCastException: Specified cast is not valid.
I'm new to writing custom ASP.NET server controls, and I'm encountering the following issue:
I have a control that inherits from System.Web.UI.HtmlControls.HtmlGenericControl. I override the control's Render method, use the HtmlTextWriter to emit some custom HTML (basically a TD tag with some custom attributes), and then call the case class' Render method.
Using the control:
<dc:Header id="header1" runat="Server" DataColumn="MemberNumber" Width="30%">Member Number</dc:Header >
The problem is that when I view my rendered HTML, the server tag is emitted to the client as well (right after the TD tag):
<dc:Header id="ctl00_ContentPlaceHolder_testData1_testData1_header1">Member Number</dc:Header>
How do I prevent this from happening?
i have created a aspx page with the script manager, update panels and so on. Now, when i use some jquery functions which are included inside the head tags, when the page is run, i find the script tags generated inside the body instead of the head tag. i'm using visual studio 2005 only.
View 2 RepliesI am building a forum and I want to use forum-style tags to let the users format their posts in a limited fashion.Currently I am using Regex to do this.As per this question:How to use C# regular expressions to emulate forum tags. The problem with this,is that the regex does not distinguish between nested tags.Here is a sample of how I implemented this method:
public static string MyExtensionMethod(this string text){return TransformTags(text);}
private static string TransformTags(string input)
{string regex = @"[([^=]+)[=x22']*(S*?)['x22]*](.+?)[/(1)]";
MatchCollection matches = new Regex(regex).Matches(input);
for (int i = 0; i < matches.Count; i++)
var tag = matches[i].Groups[1].Value;
var optionalValue = matches[i].Groups[2].Value;
var content = matches[i].Groups[3].Value;
Now,if I submit something like [quote] This user posted [quote] blah [/quote] [/quote] it does not properly detect the nested quote.Instead it takes the first opening quote tag and puts it with the first closing quote tag.Do you guys recommend any solutions?Can the regex be modified to grab nested tags?Maybe I shouldn't use regex for this?
I am wondering if aspx generated webpage content can be read on linux platforms. Is it necessary to have the Mono platform installed on the linux web-clients side ?
View 5 RepliesI am outputting the entire HTML for my server control as follows:
public override void Render(HtmlTextWriter output)
{
output.Write(myStringBuilder.ToString());
}
myStringBuilder is a StringBuilder object that is manually built in a separate private method.Is this an efficient way to do it? Or is it better to pass the HtmlTextWriter to my private method and make multiple calls to HtmlTextWriter.Write()?
I want get the last 3 tags that added to the db. My Tag table schema is:
TBL TAG:
CREATE TABLE [dbo].[tblTag](
[TagId] [int] IDENTITY(1,1) NOT NULL,
[Header] [nvarchar](200) NULL,
[IsActive] [tinyint] NULL DEFAULT ((0)),
[Ordered] [int] NOT NULL DEFAULT ((1)),
[Language] [nvarchar](5) NULL,
[DateTime] [smalldatetime] NULL,
[Official] [nvarchar](max) NULL,
[LastUpdate] [datetime] NULL,
[Locked] [tinyint] NULL,
[LastUpdateUser] [nvarchar](256) NULL,
[NumViews] [bigint] NULL,
[AllUserModified] [nvarchar](max) NULL,
CONSTRAINT [PK_tblTag] PRIMARY KEY CLUSTERED
(
[TagId] ASC
)
My TagtoMoudule table:
CREATE TABLE [dbo].[tbl_Module_Tag](
[AutoId] [int] IDENTITY(1,1) NOT NULL,
[ModuleId] [int] NOT NULL,
[ItemId] [int] NOT NULL,
[TagId] [int] NOT NULL
) ON [PRIMARY]
I want get the last 3 items in the tbl_Module_Tag but with no duplicate value, get uniq tags For exemple If the data the query "select tagid from tbl_Module_Tag order by autoid desc" return this values..........
Some of my servercontrols dont need ID's (i never need to access them from codebehind), removing them is rendering fine without comlaints. Is this ok?
why im dont want IDs? im using a .resx for different languages and from what I understand these must tied to a server control. And im tired of comming up with new pointless unique names. Also the these ID's gets insanly long as clientID.
I have a (image button)
<asp:ImageButton
ID="ImageButton1"
runat="server"
ImageUrl="../Images/checkout/Proceed_To_Checkout_Button.png"
onclick="top.location='<%=string.Format("MyAccount.aspx?action=new&returnUrl={0}",
Web.ProcessFlow.Common.QueryString(Request.QueryString["returnUrl"]))%>'"
/>
I get this error when I push the button:
Server tags cannot contain <% ... %> constructs.
I have tried <# too
it didn't help.
Morning all I have frequently used the old
<asp:Label ID="lblWas" runat="server" Text='<%# XPath("FACEVALUE") %>'></asp:Label>
This type of thing. when I first came across it I loved it, i'm using it again today but not quite so simply. I have a number of extra things I would like to achieve.
Apply formatting to the value. Like Text='<%# string.Format(XPath("FACEVALUE"), "{0:c}") %>'>
<asp:LinkButton ID="lnkBook" runat="server" PostBackUrl='/THEATRE/' + XPath("FACEVALUE")>Book</asp:LinkButton>
For option number 2 the URL is not as I would expect, and for number 1 I cannot get the syntax correct if it's even possible.
I have not been able to find something suitable in google. Hopefully what I am trying to achieve is obvious from the example :)
I want to use some server tags in OnClientClick of LinkButton
<asp:LinkButton ID="lnkbtnID" OnClientClick='<%# "window.open('SomePage.aspx?Id=" + Eval("reqID") + "');" %>' runat="server" Text='<%# Eval("reqID")%>'>
</asp:LinkButton>
how to write this, it is giving the error that Server tags are not well formed.So how to write this correctly?
Is there a way to apply your own CSS tags to <li> tags when using ASP .NET 4.0 menu control? For example, say I have an external style sheet that has tags "class1", "class2", "class3", and etc. I want to apply "class1" to the first menu item. Then if menu item is selected, I want to apply "class2" and if it's not selected, "class3". I played with various 'Static' styles, but just can't get it work. I finally gave up and created my own menu control that extends ASP .NET menu control and provides my own custom rendering. This works, but I'm wondering if there is a way to get it work with built-in menu control.
View 1 RepliesI am creating custom server control. I have two classes in project. One is main class that render control and another will be used to render content based on condition.I just want to know how to render content from other classes in main class.For example. This isjust an example.My main class code
[Code]....
My TopLeftPane class
[Code]....
My page code on page load event
[Code]....
When I run the page, Header title always getting null. This is a just sample code. I will have more than 20 classes so I dont want to write a code in main class to render whole control.I hope all of you understand my problem.
I am rendering custom control. After rendered the control it dynamically creates one span. how to remove that span. I explained it below
<span id ="CustomControl">
<div id ="CustomControl_CC" runat ="server">
rendering part
</div>
</span>
The bold part only i am rendering how it creating span
I have some rendering logic for custom markup (a'la bbcode, but not bbcode). So that when I'm getting the stuff from DB I'm then calling MyRender.ToHTML(model.text)... Now what I do today is I just have a form below and I do a post and add the item and return the same view. My question is - how to do it with ajax? Should I create a control and return HTML a'la winforms? Is that sexy? How do you do something like that? Or should I drop it? Maybe duplicate the rendering logic with javascript?
View 1 RepliesI am trying to render the Button control @ serverside with PostBackUrl properties to set to another page ""~/page1.aspx". When I click on that button , it still postback to same page , does not postback to "page1.aspx" . I am trying to implement crosspage postback. I don't know button information and postbackurl info at design time. I Only know button and PostbackUrl info @ runtime.Code I am using
protected void Page_Load(object sender, EventArgs e)
{ div1.InnerHtml = GetRenderControl(); }
public
string GetRenderControl()
{ Button buttonAdd = new Button();
[code]...
I would like to create a Server Control that change its view by a XSLT.
Something like:
<cc1:MySC ...> myXslt </cc1...>
Do you have tutorial?
I haven't been able to find relevant information through searches. I'm very green when it comes to sever side scripting. I have an ASPX page with a standard form. In the head I have meta tags, the title tag, and a link tag neatly ordered on their own lines. However, when viewing the source code after publishing to the server, the spacing between the tags is removed and it looks quite messy. (There are also <style> and <script> tags that follow, but they remain unaffected.)
I realize this has no practical effect on the site itself (in an SEO sense or otherwise). My project manager shows the source code to our clients to educate them on meta tags and page titles. It would help if it wouldn't become jumbled like this. I wonder if this is a common issue and if it's possible to prevent through better coding practices. HTML as authored, with tags separated on their own lines:
HTML Code:
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="description" content="Welcome to Lawn Care Waukesha - Cut My Lawn. Cut My Lawn - Lawn Care Services has offered quality lawn cutting, fertilizing, aerating, and much more at affordable pricing since 2002! We currently offer lawn care service to Waukesha, Brookfield, Pewaukee, Menomonee Falls, and surrounding communities." />
<meta name="keywords" content="lawn cutting, lawn mowing, lawn care, fertilizing, aeration, mulching, shrub trimming, lawn mowing, edging, pruning, mulching, weed control, waukesha, Brookfield, Pewaukee, menomonee falls" />
<title>Lawn Care Waukesha — Cut My Lawn, Lawn Care Service</title>
<link rel="shortcut icon" type="image/x-icon" href="favicon.ico" />
HTML after being processed by the sever, with all the tags running together:
HTML Code:
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><meta name="description" content="Welcome to Lawn Care Waukesha - Cut My Lawn. Cut My Lawn - Lawn Care Services has offered quality lawn cutting, fertilizing, aerating, and much more at affordable pricing since 2002! We currently offer lawn care service to Waukesha, Brookfield, Pewaukee, Menomonee Falls, and surrounding communities." /><meta name="keywords" content="lawn cutting, lawn mowing, lawn care, fertilizing, aeration, mulching, shrub trimming, lawn mowing, edging, pruning, mulching, weed control, waukesha, Brookfield, Pewaukee, menomonee falls" /><title>
Lawn Care Waukesha — Cut My Lawn, Lawn Care Service
</title><link rel="shortcut icon" type="image/x-icon" href="favicon.ico" />
I'm not sure it's relevant, but here's the script used to send the form (which I didn't write, by the way). It's the final tag inside the page head:
HTML Code:
<script type="" runat="server">
Protected Sub SubmitForm_Click(ByVal sender As Object, ByVal e As System.EventArgs)
If Not Page.IsValid Then Exit Sub
Dim SendResultsTo As String = "email"
Dim smtpMailServer As String = "smtp"
Dim smtpUsername As String = "email"
Dim MailSubject As String = "subject"
Try
Dim txtQ As TextBox = Me.FormContent.FindControl("TextBoxQ")
If txtQ IsNot Nothing Then
Dim ans As String = ViewState("hf1")
If ans.ToLower <> txtQ.Text.ToLower Or ans.ToUpper <> txtQ.Text.ToUpper Then
Me.CutMyLawnForm.ActiveViewIndex = 3.......................
I'm rendering a view for the text/plain part of an e-mail. But in some cases, the whitespace is removed between non-output server tags, and I can't figure out why. Can someone explain why the following is missing the line breaks before the final line of output?
[Code]....
But this works - whitespace is preserved between output tags:
[Code]....
This is on MVC 2. It may have been on MVC 1 (or even in Web Forms), but I didn't notice it until today when I went to add a new line to the e-mail, so not sure of the source. Does ASP.NET or MVC have some optimization to try not to output whitespace between server tags?
I have an ASP.net page which contains some controls.
I generate this controls by code, [Actually I have a method which uses a stringBuilder and add Serverside tag as flat string on it]
My page shows the content correctly but unfortunately my controls became like a Client-side control
For example I had a LoginView on my generated code which dosen't work, and also I had read some string from LocalResources which dosen't appear on the page What Should I do to make my generating method correct
here is the code
protected string CreateSubSystem(string id, string roles, string AnonymousTemplateClass, string href, string rolesContentTemplateClass, string LoggedInTemplateClass)
{
StringBuilder sb = new StringBuilder();
sb.Append("<div class="SubSystemIconPlacement" id="");
sb.Append(id);
sb.Append(""><asp:LoginView runat="server" ID="");
sb.Append(id);
sb.Append(""><AnonymousTemplate><div class="");
sb.Append(AnonymousTemplateClass);
sb.Append(""></div><asp:Label ID="lblDisabled");
sb.Append(id);
sb.Append("" runat="server" SkinID="OneColLabel" meta:resourcekey="lbl");
sb.Append(id);
sb.Append("" /></AnonymousTemplate><RoleGroups><asp:RoleGroup Roles="");
sb.Append(roles);
sb.Append(""><ContentTemplate><a class="ImageLink" href="");
sb.Append(href);
sb.Append(""><div class="");
sb.Append(rolesContentTemplateClass);
sb.Append(""></div></a><asp:HyperLink runat="server" CssClass="SubSystemText" ID="lnk");
sb.Append(id);
sb.Append(" NavigateUrl="~/");
sb.Append(href);
sb.Append(" " meta:resourcekey="lbl");
sb.Append(id);
sb.Append("" /></ContentTemplate></asp:RoleGroup></RoleGroups><LoggedInTemplate><div class="");
sb.Append(LoggedInTemplateClass);
sb.Append(""></div><asp:Label runat="server" SkinID="OneColLabel" ID="lblDisabledLoggedIn");
sb.Append(id);
sb.Append("" meta:resourcekey="lbl");
sb.Append(id);
sb.Append("" /></LoggedInTemplate></asp:LoginView>");
sb.Append("</div>");
return sb.ToString();
}
I also use this method on page_PreRender event
I have a loop in JS, and I want to pass each parameter in that loop to a function in ASP.NET in the codebehind.
something like that:
for (var i = 0; i < elements.length; i++)
{
}
And I want to pass a function in <%%> the elements[i].
How can I do that?