Forum Discussion
Trouble with WebForms app
Hello,
I do not have access to the code-behind source file. This file is not existing in the deployed app.
The aspx file contains next code fragment (this is working correctly), but very long.
<p style="font-family:Arial;font-size: 9pt;color:black" class="bla">
<%# ProductService.GetProductVariantName((OrderProductVariant)Container.DataItem,
LanguageId)%><strong><%# (((OrderProductVariant)Container.DataItem).ProductVariant.Name
== "Kuldne keskmine" || ((OrderProductVariant)Container.DataItem).ProductVariant.Name ==
"Aukso vidurys" ) &&
((OrderProductVariant)Container.DataItem).ProductVariant.Product.TemplateId == 4 ? "
GĖLIŲ VAZA" : (((OrderProductVariant)Container.DataItem).ProductVariant.Name ==
"Luksuslik" || ((OrderProductVariant)Container.DataItem).ProductVariant.Name == "Deluxe")
&& ((OrderProductVariant)Container.DataItem).ProductVariant.Product.TemplateId == 4 ? "
GĖLIŲ VAZA" : "" %></p>
I want to save the for the example
OrderProductVariant)Container.DataItem).ProductVariant.Name
in variable and use that variable instead of this long one. There should I put this variable declaration?
2 Replies
- AddWebSolutionBrass ContributorHi jaakivask,
In a WebForms application, you can declare and use variables in the code-behind file associated with the corresponding .aspx page. Since you mentioned that you do not have access to the code-behind source file, you may face limitations in making such changes. However, I'll provide guidance on where you would typically declare a variable in the code-behind file.
Locate the Code-Behind File:
The code-behind file is associated with the .aspx page and usually has the same name as the .aspx page with a ".aspx.cs" or ".aspx.vb" extension for C# or VB.NET, respectively.
Add a Variable Declaration:
Open the code-behind file in a code editor.
Inside the class associated with the .aspx page, you can declare a variable. For example, you can declare the variable at the class level to make it accessible throughout the class.
public partial class YourPageName : System.Web.UI.Page
{
// Declare a variable at the class level
private string productVariantName;
// Other code...
// Event handler or method where you want to assign a value to the variable
protected void Page_Load(object sender, EventArgs e)
{
// Assign a value to the variable
productVariantName = ((OrderProductVariant)Container.DataItem).ProductVariant.Name;
// Other code...
}
// Other methods or event handlers...
}
Use the Variable in Your Markup:
Once the variable is declared at the class level, you can use it in your markup within the .aspx file.
<p style="font-family:Arial;font-size: 9pt;color:black" class="bla">
<%# ProductService.GetProductVariantName((OrderProductVariant)Container.DataItem, LanguageId) %>
<strong>
<%# (productVariantName == "Kuldne keskmine" || productVariantName == "Aukso vidurys") && ((OrderProductVariant)Container.DataItem).ProductVariant.Product.TemplateId == 4 ? "GĖLIŲ VAZA" :
(productVariantName == "Luksuslik" || productVariantName == "Deluxe") && ((OrderProductVariant)Container.DataItem).ProductVariant.Product.TemplateId == 4 ? "GĖLIŲ VAZA" : "" %>
</strong>
</p>
Remember to replace "YourPageName" with the actual name of your .aspx page, and make sure to save your changes and recompile the application. If you don't have access to the code-behind file, you might need to work with the development team or the person responsible for maintaining the code to make these modifications.
Here you can refer the link also
https://stackoverflow.com/questions/4029467/broken-link-between-aspx-and-aspx-cs-files
Thanks & Best Regards,
AddWebSolution - PasildaDataCopper Contributor
jaakivask Looks like you should be able to use somthing like this after your <strong> tag:
<% string pvname = ((OrderProductVariant)Container.DataItem).ProductVariant.Name; //... %>then find/replace with the variable name.
A quick glance at the code suggests that the two ternery operators are testing the same thing and both rely on ((OrderProductVariant)Container.DataItem).ProductVariant.Product.TemplateId
If this is correct, than that part of the code could be more legible like this (I added the closing strong tag):
<% string pvname = ((OrderProductVariant)Container.DataItem).ProductVariant.Name; int pvtemplate = ((OrderProductVariant)Container.DataItem).ProductVariant.Product.TemplateId; string display = (pvtemplate == 4 && (pvname == "Kuldne keskmine" || pvname == "Aukso vidurys" || pvname == "Luksuslik" || pvname == "Deluxe")) ? " GĖLIŲ VAZA" : ""; %> <strong><%# display%></strong>