I need to update sitefinity Telerik.Sitefinity.Frontend.Lists dll (version 10.1.6544).
When I decompiled this dll through JustDecomplile Tool, I got tpye error on
typeof(Tuple).Create File \SitefinityFrontendLists\Sitefinity.Frontend.Lists\MVC.Views.Lists\List_AnchorList.cs
Please check this issue and suggest a way to decompile and update sitefinity dlls
using Microsoft.CSharp.RuntimeBinder;
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Web.Mvc;
using System.Web.WebPages;
using System.Web.WebPages.Instrumentation;
using Telerik.Sitefinity.Frontend.Lists.Mvc.Models;
using Telerik.Sitefinity.Frontend.Mvc.Helpers;
using Telerik.Sitefinity.Frontend.Mvc.Models;
namespace Telerik.Sitefinity.Frontend.Lists.MVC.Views.Lists
{
[GeneratedCode("RazorGenerator", "2.0.0.0")]
[PageVirtualPath("~/MVC/Views/Lists/List.AnchorList.cshtml")]
public class List_AnchorList : WebViewPage<ContentListViewModel>
{
public List_AnchorList()
{
}
public override void Execute()
{
this.WriteLiteral("\n<div");
PositionTagged<string> positionTagged = Tuple.Create<string, int>(" class=\"", 194);
PositionTagged<string> positionTagged1 = Tuple.Create<string, int>("\"", 217);
AttributeValue[] attributeValueArray = new AttributeValue[] { Tuple.Create<Tuple<string, int>, Tuple<object, int>, bool>(Tuple.Create<string, int>("", 202), Tuple.Create<object, int>(base.Model.CssClass, 202), false) };
this.WriteAttribute("class", positionTagged, positionTagged1, attributeValueArray);
this.WriteLiteral(">\n\n");
foreach (ItemViewModel item in base.Model.Items)
{
this.WriteLiteral(" <h1 ");
this.Write(base.Html.InlineEditingAttributes(base.Model.ProviderName, base.Model.ContentType.FullName, (Guid)((dynamic)item.Fields).Id));
this.WriteLiteral(">\n <a");
this.WriteAttribute("id", Tuple.Create<string, int>(" id=\"", 393), Tuple.Create<string, int>("\"", 417), typeof(Tuple).Create(Tuple.Create<string, int>("", 398), typeof(Tuple).Create<object, int>(((dynamic)item.Fields).Id, 398), false), Tuple.Create<Tuple<string, int>, Tuple<string, int>, bool>(Tuple.Create<string, int>("", 413), Tuple.Create<string, int>("-Top", 413), true));
this.WriteLiteral("\n ");
this.Write(base.Html.InlineEditingFieldAttributes("Title", "ShortText"));
this.WriteLiteral("\n href=\"#");
this.Write(((dynamic)item.Fields).Id);
this.WriteLiteral("\">");
this.Write(((dynamic)item.Fields).Title);
this.WriteLiteral("</a>\n </h1>\n");
this.WriteLiteral(" <ul>\n");
foreach (ItemViewModel itemViewModel in ((ListViewModel)item).ListItemViewModel.Items)
{
this.WriteLiteral(" <li ");
this.Write(base.Html.InlineEditingAttributes(base.Model.ProviderName, ((ListViewModel)item).ListItemViewModel.ContentType.FullName, (Guid)((dynamic)itemViewModel.Fields).Id));
this.WriteLiteral(">\n <a ");
this.Write(base.Html.InlineEditingFieldAttributes("Title", "ShortText"));
this.WriteLiteral("\n href=\"#");
this.Write(((dynamic)itemViewModel.Fields).Id);
this.WriteLiteral("\">");
this.Write(((dynamic)itemViewModel.Fields).Title);
this.WriteLiteral("</a>\n </li>\n");
}
this.WriteLiteral(" </ul>\n");
}
this.WriteLiteral("\n");
foreach (ItemViewModel item1 in base.Model.Items)
{
this.WriteLiteral(" <h1 ");
this.Write(base.Html.InlineEditingAttributes(base.Model.ProviderName, base.Model.ContentType.FullName, (Guid)((dynamic)item1.Fields).Id));
this.WriteLiteral("\n");
this.WriteLiteral(" ");
this.Write(base.Html.InlineEditingFieldAttributes("Title", "ShortText"));
this.WriteLiteral("\n id=\"");
this.Write(((dynamic)item1.Fields).Id);
this.WriteLiteral("\">\n");
this.WriteLiteral(" ");
this.Write(((dynamic)item1.Fields).Title);
this.WriteLiteral("\n </h1>\n");
foreach (ItemViewModel itemViewModel1 in ((ListViewModel)item1).ListItemViewModel.Items)
{
this.WriteLiteral(" <div ");
this.Write(base.Html.InlineEditingAttributes(base.Model.ProviderName, ((ListViewModel)item1).ListItemViewModel.ContentType.FullName, (Guid)((dynamic)itemViewModel1.Fields).Id));
this.WriteLiteral(">\n <h3 ");
this.Write(base.Html.InlineEditingFieldAttributes("Title", "ShortText"));
this.WriteLiteral("\n id=\"");
this.Write(((dynamic)itemViewModel1.Fields).Id);
this.WriteLiteral("\">\n");
this.WriteLiteral(" ");
this.Write(((dynamic)itemViewModel1.Fields).Title);
this.WriteLiteral("\n </h3>\n\n <div ");
this.Write(base.Html.InlineEditingFieldAttributes("Content", "LongText"));
this.WriteLiteral(">");
this.Write(base.Html.Raw(((dynamic)itemViewModel1.Fields).Content));
this.WriteLiteral("</div>\n\n <p><a");
this.WriteAttribute("href", Tuple.Create<string, int>(" href=\"", 1937), Tuple.Create<string, int>("\"", 1964), Tuple.Create<Tuple<string, int>, Tuple<string, int>, bool>(Tuple.Create<string, int>("", 1944), Tuple.Create<string, int>("#", 1944), true), typeof(Tuple).Create(Tuple.Create<string, int>("", 1945), typeof(Tuple).Create<object, int>(((dynamic)item1.Fields).Id, 1945), false), Tuple.Create<Tuple<string, int>, Tuple<string, int>, bool>(Tuple.Create<string, int>("", 1960), Tuple.Create<string, int>("-Top", 1960), true));
this.WriteLiteral(">");
this.Write(base.Html.Resource("BackToTop", false));
this.WriteLiteral("</a></p>\n </div>\n");
}
}
this.WriteLiteral("\n</div>\n");
}
}
}
I'm not sure why you need to decompile anything. JustDecompile really does as good as it can. But these assemblies are available on GitHub too. https://github.com/Sitefinity/feather-widgets
Related
In my .razor page I have an InputText, what I want is to update that number as soon as it is being typed, specifically is to put a space every 4 characters, how am I trying to do it?
<InputText #bind-Value="oPagos.NumeroEnTarjeta" #onkeydown="#Tecleando" type="number"
onchange="()=>NumberChanged()" id="card-number" placeholder="1111 2222 3333 4444" class="input" maxlength="16" />
Then,
public void Tecleando(KeyboardEventArgs e)
{
//Console.WriteLine(e.Key);
oPagos.NumeroEnTarjeta = generateSpaces(oPagos.NumeroEnTarjeta);
Console.WriteLine(oPagos.NumeroEnTarjeta);
}
I have a function where I plan to take all the value from the bind, ie: oPayments.NumberOnCard, and every 4 spaces generate a space.
This does not work for me for two reasons.
the first number that I type is taken from the #Onkeydown event but the variable oPagos.NumeroEnTarjeta is empty.
I don't know how to update the value of the InputText, as I show in the following image I effectively modify the variable oPagos.NumeroEnTarjeta, but I can't get the user to see it rendered in the text box.
Should I take another way or how do I fix what I have? Thank you.
Update
I succeeded in doing something similar, but with two different events, onblur and onfocus.
I use onfocus to remove the spaces and I use onblur to add my spaces, however, what I would like to do is while I'm writing
I got some Problems with Dynamic Data using Bind-Value / Bind so i started using Blazorise and solve my problems, a possible solution is this one:
<Field>
<TextEdit Text="#opagos.NumeroEnTarjeta" TextChanged="#MethodThatBringSpaces"></TextEdit>
<Field>
Then in #code
Task MethodThatBringSpaces(string value){
opagos.NumeroEnTarjeta = generateSpaces(value);
}
Also you can use the data that you want (i use string in this case) and you can add the same things than blazor (id,placeholder,etc.)
Here's a set of code which I think does basically what you want. It was written to answer a similar question on here a few months ago! I've used dashes instead of spaces to show the space being filled. It's was coded in Net6.0 but should be Ok in Net5.0.
You will probably need to tweak it a little to fit your exact needs:
CreditCardCode.razor
#namespace StackOverflowAnswers.Components
#inherits InputBase<string>
<input #attributes="AdditionalAttributes"
class="#CssClass"
value="#stringValue"
#oninput="OnInput"
#onchange="this.OnValueChanged"
#onfocus="OnFocus"
#onblur="OnBlur"
/>
CreditCardCode.razor.cs
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Forms;
using Microsoft.AspNetCore.Components.Web;
using System.Text.RegularExpressions;
namespace StackOverflowAnswers.Components;
public partial class CreditCardCode : InputBase<string>
{
private string stringValue = String.Empty;
private string _currentValue = String.Empty;
// Sets up the initial value of the input
protected override void OnInitialized()
{
_currentValue = this.Value ?? string.Empty;
this.stringValue = this.GetCodeValue(_currentValue);
base.OnInitialized();
}
private async Task OnInput(ChangeEventArgs e)
{
var rawValue = e.Value?.ToString();
stringValue = "";
await Task.Yield();
_currentValue = this.GetCodeValue(rawValue ?? string.Empty);
this.stringValue = this.FormatValueAsString(_currentValue);
}
private async Task OnFocus(FocusEventArgs e)
{
stringValue = "";
await Task.Yield();
this.stringValue = this.FormatValueAsString(_currentValue);
}
private async Task OnBlur(FocusEventArgs e)
{
stringValue = "";
await Task.Yield();
this.stringValue = this.GetCodeValue(_currentValue);
}
// We set the base CurrentValueAsString to let it handle all the EditContext changes and validation process
private void OnValueChanged(ChangeEventArgs e)
=> this.CurrentValueAsString = e.Value?.ToString() ?? string.Empty;
// Necessary override for InputBase
protected override bool TryParseValueFromString(string? value, out string result, out string validationErrorMessage)
{
result = value ?? string.Empty;
if (!string.IsNullOrEmpty(value) && value.Length == 19)
{
validationErrorMessage = string.Empty;
return true;
}
else
{
validationErrorMessage = "Value must be nnnn-nnnn-nnnn-nnnn";
return false;
}
}
protected override string FormatValueAsString(string? value)
=> value ?? string.Empty;
private string GetCodeValue(string value)
{
value = new string(value.Where(c => char.IsDigit(c)).ToArray());
value = value.Length > 16
? value.Substring(0, 16)
: value;
var reg = new Regex(#"([0-9]{1,4})");
var matches = reg.Matches(value);
var outvalue = string.Empty;
if (matches.Count > 0)
{
foreach (Match match in matches)
{
outvalue = $"{outvalue}-{match.Value}";
}
outvalue = outvalue.Trim('-');
return outvalue;
}
return string.Empty;
}
}
Test Page
#page "/"
#using StackOverflowAnswers.Components
<h3>EditForm</h3>
<div class="container-fluid">
<EditForm EditContext=editContext>
<div class="row">
<div class="col-2">
Credit Card No:
</div>
<div class="col-4">
<CreditCardCode class="form-control" #bind-Value="this.model.CreditCardNo"/>
</div>
<div class="col-4">
<ValidationMessage For="() => this.model.CreditCardNo" />
</div>
</div>
</EditForm>
<div class="row">
<div class="col-2">
Credit Card No:
</div>
<div class="col-4">
#model.CreditCardNo
</div>
</div>
</div>
#code {
private EditContext? editContext;
private ModelData model = new ModelData();
protected override Task OnInitializedAsync()
{
this.editContext = new EditContext(model);
return Task.CompletedTask;
}
class ModelData
{
public string CreditCardNo { get; set; } = string.Empty;
}
}
I am trying to pass a dictionary as a parameter to a blazor component. The dictionary needs to store <string, dynamic>, <string, List>, and <string, Dictionary<string, dynamic>> key-value pairs.
I tried to do this, but get the error, "'EventCallbackFactory' has no applicable method named 'CreateBinder' but appears to have an extension method by that name. Extension methods cannot be dynamically dispatched."
Is what I am trying to do valid, and if not, why? Is there another way I should approach this?
Here is the code for my blazor component, for reference:
#page "/dictitemcomponent"
#using System.Collections.Generic;
<ul>
#foreach (KeyValuePair<string, dynamic> item in thisDict)
{
#if(item.Value.GetType() == typeof(Dictionary<string, dynamic>))
{
<li>#item.Key.ToString() : </li>
#foreach (var dict in item.Value)
{
<DictItemComponent thisDict=dict/>
}
}
#if(item.Value.GetType() == typeof(List<dynamic>))
{
<li>#item.Key.ToString() : </li>
#foreach (var value in item.Value)
{
<li>#value</li>
}
}
#if(item.Value.GetType() != typeof(List<dynamic>) && item.Value.GetType() != typeof(Dictionary<dynamic, dynamic>))
{
<li>#item.Key.ToString() : <input #bind="item.Value"/></li>
}
}
</ul>
#code
{
public KeyValuePair<string, dynamic> newProperty = new KeyValuePair<string, dynamic>();
[Parameter] public Dictionary<string,dynamic> thisDict {get; set;}= new Dictionary<string, dynamic>();
//convert the value of a KVP to a dictionary
public void ValueToProperty(KeyValuePair<string,dynamic> property)
{
string key = property.Key;
property = new KeyValuePair<string, dynamic>(key, new Dictionary<string, dynamic>());
}
public void ValueToList(KeyValuePair<string,dynamic> property)
{
string key = property.Key;
property = new KeyValuePair<string, dynamic>(key, new List<dynamic>());
}
}
May I know what you are trying to achieve?
Based on your first if statement, why would you have a dictionary inside a dictionary?
By reading your exception and your 3rd conditional statement, it seems that you are trying to bind the input to your dictionary value. However, this is not how you should use a dictionary. Unless you are binding to the usual "type" property (e.g. string), you may use #bind=someVariable. Otherwise, in a dictionary, each value should tie to their respective key and therefore, #bind=_dict[key] ("shorthand" syntax for #bind-value and #bind-value:event) instead of binding input to the item.value. For easier understanding, I've scoped out the aforementioned conditional statement and simulated a solution to the problem in the following lines. It should render value in the <label> next to the input during onchange:
#page "/dict"
#foreach (var kvp in _dict)
{
<div>
<label>#kvp.Key</label>
<input #bind=_dict[kvp.Key] />
<label>Key:#kvp.Key|Value:#kvp.Value</label>
}
#code {
private Dictionary<string, string> _dict = new()
{
["1"] = "One",
["2"] = "Two",
["3"] = "Three",
["4"] = "Four",
["5"] = "Five",
};
}
Meanwhile, you should simplify your if statements as follow:
#if(item.Value.GetType() == typeof(Dictionary<string, dynamic>))
{
//dowork
}
else if(item.Value.GetType() == typeof(List<dynamic>))
{
//do more work
}
else
{
//do other work
}
Screenshot for my Input fields rendered based on Key Value Pair and value entered
I'm attempting to change a query string paramater without reloading the page. I have a DateTime Date value that I'm attempting to turn into a string and put into the url. Say, for the sake of this question that it is:
DateTime? Date = new DateTime(2020, 9, 4);
So, my url could begin looking like:
https://localhost:44346/Events?d=2020-10-18
and after I do whatever magic must be done, it ends up like:
https://localhost:44346/Events?d=2020-10-04
I have attempted using NavigationManager and QueryHelpers like the following, but I've had no luck:
QueryHelpers.AddQueryString(navManager.Uri, "d", Date?.ToString("yyyy-MM-dd"));
Please check out this demo
#page "/counter"
#using Microsoft.AspNetCore.WebUtilities
#using System.Web
#inject NavigationManager navManager
<button class="btn btn-primary" #onclick="ChangeUrl">Change url</button>
<br />
demonstrate lack of page reload
<br />
<button class="btn btn-primary" #onclick="AddItem">Add item</button>
#foreach (var item in list)
{
#item
}
#code {
private List<string> list = new List<string>()
{
"Test string"
};
private void AddItem()
{
var uri = navManager.ToAbsoluteUri(navManager.Uri);
if (QueryHelpers.ParseQuery(uri.Query).TryGetValue("d", out var param))
{
list.Add(param.First());
}
else
{
list.Add("d is empty");
}
}
DateTime dateCounter = DateTime.Today;
private void ChangeUrl()
{
dateCounter = dateCounter.AddDays(1);
string url = RemoveQueryStringByKey(navManager.Uri, "d");
var query = new Dictionary<string, string> { { "d", dateCounter.ToString("dd-MM-yyyy") } };
navManager.NavigateTo(QueryHelpers.AddQueryString(url, query));
}
public static string RemoveQueryStringByKey(string url, string key)
{
var uri = new Uri(url);
// this gets all the query string key value pairs as a collection
var newQueryString = HttpUtility.ParseQueryString(uri.Query);
// this removes the key if exists
newQueryString.Remove(key);
// this gets the page path from root without QueryString
string pagePathWithoutQueryString = uri.GetLeftPart(UriPartial.Path);
return newQueryString.Count > 0
? String.Format("{0}?{1}", pagePathWithoutQueryString, newQueryString)
: pagePathWithoutQueryString;
}
}
is it possible to use Razor syntax to build a countdown timer in Pages (asp .net core 3.1) project.
if yes, please share the steps and code snippets. I am trying to use c# only with razor view (# {} ) only. sometime like this.
#{
string message = "";
Timer timer;
void TickTimer(Object sender)
{
// do something
}
timer = new Timer(new TimerCallback(TickTimer), null, 1000, 1000);
}
It can be implemented in blazor:
#using System.Threading;
<h1>#Count</h1>
<button #onclick=#StartCountdown>Start Timer</button>
#functions {
private int Count { get; set; } = 10;
void StartCountdown()
{
var timer = new Timer(new TimerCallback(_ =>
{
if (Count > 0)
{
Count--;
InvokeAsync(() =>
{
StateHasChanged();
});
}
}), null, 1000, 1000);
}
}
We just switched target framework in our ASP.NET web application from 3.5 to 4.0. We ran into the following problem:
We have a couple of custom controls that worked fine in 3.5 but now with 4.0 they are not persisted in ViewState, one of them is basically a wrapper for other controls that inherits the Label class and the aspx-code looks like this:
<fsc:FormLabel ID="l_purchaserNo" runat="server" CssClass="label" Text="Purchaser">
<asp:TextBox ID="tb_purchaserNo" runat="server" CssClass="textBox" MaxLength="50" />
</fsc:FormLabel>
and the resulting html is:
<span id="l_purchaserNo" class="label">
<label class="header" for="tb_purchaserNo">Purchaser</label>
<span class="valueContainer">
<input name="tb_purchaserNo" type="text" id="tb_purchaserNo" class="textBox" />
</span>
</span>
So the control basically just adds a few span-tags and a label that is connected to the textbox.
After postback the html-code in 4.0 was:
<span id="l_purchaserNo" class="label"></span>
i.e. everything within the outer wrapper was gone and anything entered in the textbox could not be retreived from code behind.
Below you find the code for our FormLabel class.
We found that by setting ViewStateMode=Disabled on our custom control fsc:FormLabel and ViewStateMode=Enabled on the asp:TextBox the inner controls where persisted to ViewState but at the same time we lost ViewState on the wrapper and since we translate the text on the wrapper label we need viewstate for this as well (actually we tried every combination and setting ViewStateMode=Enabled on fsc:FormLabel did not help, regardless of how we set the ViewStateMode on the page). EnableViewState is true on all levels.
Could someone tell us how to get ViewState to work as before in 3.5, on ALL controls - wrapper as well as wrapped controls?
Thanks
Christian, Zeljko, Jonas
using System;
using System.Collections.Generic;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace FormLabel
{
public class FormLabel : Label
{
private bool HasChildren
{
get
{
return Controls.Count > 0;
}
}
public override string Text
{
get
{
if (!HasChildren)
{
return base.Text;
}
var text = ViewState[ID + "Text"] as String;
if (text != null)
{
((LiteralControl)Controls[0]).Text = text;
}
return ((LiteralControl)Controls[0]).Text;
}
set
{
if (!HasChildren)
{
base.Text = value;
return;
}
((LiteralControl)Controls[0]).Text = value;
}
}
public void SetText(string text)
{
((LiteralControl)Controls[0]).Text = text;
ViewState[ID + "Text"] = text;
}
public bool IndicateRequired
{
get
{
object state = ViewState[String.Format("{0}_IR", ID)];
return state != null && (bool)state;
}
set
{
ViewState[String.Format("{0}_IR", ID)] = value;
}
}
protected override void OnLoad(EventArgs e)
{
ViewState[ID + "Text"] = Text;
base.OnLoad(e);
}
protected override void Render(HtmlTextWriter writer)
{
if (HasChildren)
{
List<Control> controls = Controls.GetControls();
List<BaseValidator> validators = Controls.GetValidators();
WriteLabelControl(writer);
WriteRequiredIndicator(writer);
WriteControlHeader(writer, validators, this.GetFirstControl());
WriteInnerControls(writer, controls);
WriteLabelEndControl(writer);
return;
}
base.Render(writer);
}
private void WriteLabelControl(HtmlTextWriter writer)
{
writer.WriteBeginTag("span");
writer.WriteAttribute("id", ClientID);
writer.WriteAttribute("class", CssClass);
foreach (string attributeKey in Attributes.Keys)
{
writer.WriteAttribute(attributeKey, Attributes[attributeKey]);
}
writer.Write(HtmlTextWriter.TagRightChar);
}
private void WriteRequiredIndicator(HtmlTextWriter writer)
{
if (IndicateRequired)
{
writer.WriteBeginTag("span");
writer.WriteAttribute("class", "requiredIndicator");
writer.Write(HtmlTextWriter.TagRightChar);
writer.WriteEndTag("span");
}
}
private void WriteControlHeader(HtmlTextWriter writer, IEnumerable<BaseValidator> validators, Control userControl)
{
writer.WriteBeginTag("label");
writer.WriteAttribute("class", "header");
if (userControl != null)
{
writer.WriteAttribute("for", userControl.ClientID);
}
writer.Write(HtmlTextWriter.TagRightChar);
writer.Write(Text);
foreach (BaseValidator validator in validators)
{
validator.CssClass = "Error";
validator.RenderControl(writer);
}
writer.WriteEndTag("label");
}
private static void WriteInnerControls(HtmlTextWriter writer, IList<Control> controls)
{
writer.WriteBeginTag("span");
writer.WriteAttribute("class", "valueContainer");
writer.Write(HtmlTextWriter.TagRightChar);
for (int i = 1; i < controls.Count; i++)
{
controls[i].RenderControl(writer);
}
writer.WriteEndTag("span");
}
private static void WriteLabelEndControl(HtmlTextWriter writer)
{
writer.WriteEndTag("span");
}
}
#region Nested type: Extensions
public static class Extensions
{
public static List<BaseValidator> GetValidators(this ControlCollection controls)
{
var validators = new List<BaseValidator>();
foreach (Control c in controls)
{
if (c is BaseValidator)
{
validators.Add(c as BaseValidator);
}
}
return validators;
}
public static List<Control> GetControls(this ControlCollection controls)
{
var listcontrols = new List<Control>();
foreach (Control c in controls)
{
if (!(c is BaseValidator))
{
listcontrols.Add(c as Control);
}
}
return listcontrols;
}
public static Control GetFirstControl(this Control container)
{
return (new InputControlFinder().FindFirstInputControl(container));
}
private class InputControlFinder
{
public Control FindFirstInputControl(Control control)
{
Control input = null;
foreach (Control child in control.Controls)
{
if (child is TextBox || child is DropDownList || child is CheckBox)
{
input = child;
}
else
{
input = FindFirstInputControl(child);
}
if (input != null)
{
return input;
}
}
return input;
}
}
}
#endregion
}