How To Display Returned Value From A Method
Dec 6, 2010[Code]....
How to display Id calling GetId() method?
[Code]....
How to display Id calling GetId() method?
I have several labels in my application, and I need to manipulate every single one of them. So, I thought the easiest way would be to simply call the manipulating C# method from the aspx page when needed, but oh, I was wrong. I have spent a couple of hours now trying to figure out how to do this, but I have not come to a solution ..
Aspx page:
<asp:Label runat="server" Text='<%= ManipulateLabel("Information") %>'></asp:Label>
Code behind (C#):
protected string ManipulateLabel(string label)
{
return label+" some value";
}
I do not wish to assign each label to value directly from code behind (normally I would do it like this but this time there are so many labels that need a manipulated value that it simply would be too hard updating the application in the future).
When using the code behind, the application simply prints "<%= ManipulateLabel("Information") %>" on the page, which is not what I want :( Also, if I use:
<span><%= ManipulateLabel("Information") %></span>
, it suddenly works. But, I need to use the asp.net web controls, not normal HTML tags.
I have a validation method,
public string ValidateField() {
string strtemp = "";
strtemp += ValidateField("Visitor_Name", visitor_name.Text, 10, 50, "string", true);
strtemp += ValidateField("Phone_Number", phone_number.Text, 5, 20, "string", true);
strtemp += ValidateField("Contact_Number", contact_number.Text, 4, 25, "string", true);
strtemp += ValidateField("Visited_Date", DropDownList1.SelectedValue, 1, 30, "int", true);
//strtemp += ValidateField("V_Id", v_id.SelectedValue, 2, 35, "int", false);
[Code] ....
And inside the button click event the validation working like
if (ValidateField() == "") {
output = usbll.insertBAL(userval);
Response.Write("Record inserted successfully");
}
It is working correctly...But It is not showing error message.So how to show the error message that is returned from the above condition ValidateField()...If the condition not satisfied i want to show a error message like length should be greater than or equal to minimum length and so on ..
For a web application developed on ASP.NET, we are finding that for user control files (ascx) we are returning long strings as a result of method calls. These are embedded in the ascx pages using the special tags <% %>When performing memory dump analysis for the application, we find that many of those strings are not being garbage collected. Also, the ascx pages are compiled to temporary DLLs and they are held in memory. Is this responsible for causing the long strings to remain in memory and not be garbage collected ?
View 2 RepliesI have the following action:
[Code]....
This returns a String. I suposed that is the correct way to return a string.
How can I call this action from a view and display the string that is being returned?
Markup:
<asp:GridView ID="GridView1" runat="Server">
<Columns>
<asp:BoundField DataField="status_column" HeaderText="Status" />
<asp:BoundField ...
<asp:BoundField ...
</Columns>
</asp:GridView>
Code:
GridView1.DataSource = _dataSet
DataBind()
The values stored in my database are integers, 1 - 9. Each value has an associated string value that I want displayed in my GridView. Ex: 1 = "Active"; 2 = "On Hold"; etc. How would I filter the incoming data so I can display the associated String value instead of the Integers from my table?
I have this code:
Dim Result As New DataTable
DataAdapter.Fill(Result)
'bind data to visible surname/name grid
If Result.Rows.Count = 0 Then
NoInputBottom.Text = "No Results. Please widen your search criteria and try again"
NoInputTop.Text = "No Results. Please widen your search criteria and try again"
Else
GV.DataSource = Result
GV.DataBind()
End If
I have also tried moving the check to the gridview like so:
If GV.Columns.Count = 0 Then
NoInputBottom.Text = "No Options Selected: Please select your search criteria and try again" NoInputTop.Text = "No Options Selected: Please select your search criteria and try again" End If
When I run the code. the noinput labels do not have value, the null check seems to be failing? how to display a message if the search returned no reults.
I have the following javascript:
$.post("/Authenticated/DeletePage/" + PageId);
showStatus("Page deleted...", 10000);
I would like to instead pass showStatus() text that is returned by the $.post() call, rather than hardcoded text. How do I do this?
In HomeController i have set the view data values (ViewData["message"] = "World!";)..
After assigned value it returned to Index page to show. In index page i used code <%= ViewData["message"] %>.. But it didnt display anything.. What is wrong in my code..
Exsits any way to modify the temporary folder path returned by System.IO.Path.GetTempPath() method?
My asp.net application run under iis 7.
I implemented PreviousPage to get data from previous page for my search function and display the returned data into a gridview. The gridview's allowpaging is enabled, but every time I go to next page, my previous page data is lost... how can I resolve that?
View 19 RepliesHow do display a list of data returned from the database like this.
[code]....
I have a gridview and would like to display one of 5 icons depending on the value returned from the database for that row (simply just A, B, C, D or E). Which event in my datagrid should I be looking at to check what value I'm getting? I presume once I can check a value I can simply set an image source using if statements?
View 4 RepliesI am using a nested listview to display a seperate grid for each group of data returned from my db query. To get this working, I have adapted a piece of code to group the data prior to it being bound:
[Code]....
I am then using the following html markup:
[Code]....
[Code]....
This works as I want it to however some of the fields within the nested table need to be formatted as currency so I am trying to use Eval and {0:c} to do this however the moment I use Eval, the data items cannot be found
DataBinding: 'System.Data.DataRow' does not contain a property with the name '0'.
My instructor gave us example code that is very similiar to the code below. I haven't heard back from him yet and wanted to find out why my code won't work properly. Could someone give me some advice on what I'm doing wrong or an easier method to display images.
<%@ WebHandler Language="VB" Class="images" %>
Imports System
Imports System.Web
Imports System.Data.SqlClient
Public Class images : Implements IHttpHandler
Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
Dim id As String = context.Request.QueryString("ImageId")
Dim userId As Integer = 4
Dim conn As New System.Data.SqlClient.SqlConnection
Dim cmd As New System.Data.SqlClient.SqlCommand
conn.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
cmd.Connection = conn
cmd.CommandText = "SELECT Image FROM mrg_Image WHERE UserId=@userId"
cmd.Parameters.AddWithValue("@userId", userId)
conn.Open()
Dim file_bytes As Byte() = cmd.ExecuteScalar()
Dim file_bytes_stream As New System.IO.MemoryStream(file_bytes)
'During the build - The next line of code is highlighted green with the error message of, "Parameter is invalid"
Dim the_image As New System.Drawing.Bitmap(file_bytes_stream)
context.Response.ContentType = "image/jpg"
the_image.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg)
conn.Close()
End Sub
Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
Get
Return False
End Get
End Property
End Class
I am creating an Asp.net web site which will support dynamic data. When I am creating a dynamic web site from Scratch (from template in VS) all is working fine. But when I am trying to add dynamic entity (.edmx) file and running the application I am getting following error
"The method 'Skip' is only supported for sorted input in LINQ to Entities. The method 'OrderBy' must be called before the method 'Skip'. "
I have an ObjectDataSource that I want to perform updates using a business entity i.e. Type="Object"). Since the values for the entity are within a user control, I have stored a reference to the control in Session and in the updating event, set the new instance to the value of the entity from the user contol property (which also pulls values from the form viaother properties of the control):
Protected Sub MasterDataSource_Updating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ObjectDataSourceMethodEventArgs) Handles MasterDataSource.Updating
Dim entity As New Login()
Dim accountControl As AccountInfo = TryCast(Session("AccountCtrl"), AccountInfo)
entity = accountControl.Entity
e.InputParameters.Add("entity", entity)
End Sub
And here's the markup for the datasource:
<asp:ObjectDataSource ID="MasterDataSource" runat="server" EnableCaching="true" CacheDuration="10"
SelectMethod="SelectAll" UpdateMethod="Update" TypeName="Data.DAL.LoginDAL">
</asp:ObjectDataSource>
My question is, how can I get the update method to pass this entity to the update method in my BLL class? It seems the Update method requires an ID or reference to the original object to use in determining whether any changes have taken place, but I don't really want to do this. In other words, I just want to use the Update event on my ObjectDataSource to pass my entity to the method ("Update") I set as a property and then let this business method handle the update of the data. Shown below, is the BLL update method I want to call:
Public Overloads Function Update(ByVal entity As Login)
If entity Is Nothing Then
Throw New ArgumentNullException("entity")
End If
MyBase.Update("UpdateLogin", entity.Username, entity.Password, entity.FirstName, entity.LastName, entity.Role, entity.Region, _
entity.Email, entity.Title, entity.TierID, entity.Street, entity.City, entity.State, entity.Zip, entity.Mobile, entity.Phone, entity.Fax)
End Function
When I try to call this as it stands now, I get an error: ObjectDataSource 'MasterDataSource' could not find a non-generic method 'Update' that has parameters: ID, entity. Previously, I'd set up a long list of parameters of basic data types (string, int, boolean), but this is rather cumbersome and I was hoping to use an entity for this (FYI, I also got the same type of error when I tried this approach, but with the ID as the
last parameter in the list). Perhaps what I'm doing here is atypical to how the ODS is normally used?? Has anyone done something like this successfully?
I have an application that has JS calling ASMX files to do asyncronous requests, using ASP.NET AJAX.
The problem is that I use always the same "onError" function, and now I don't know how to identify the method that rised the error, and it is giving me a lot of problems to debug errors. The parameter "data" of the onError method does not give enough information, for
example:
en System.ComponentModel.BaseNumberConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)
en System.Web.Script.Serialization.ObjectConverter.ConvertObjectToTypeInternal(Object o, Type type, JavaScriptSerializer serializer, Boolean throwOnError, Object& convertedObject)
en System.Web.Script.Serialization.ObjectConverter.ConvertObjectToTypeMain(Object o, Type type, JavaScriptSerializer serializer, Boolean throwOnError, Object& convertedObject)
en System.Web.Script.Serialization.ObjectConverter.ConvertObjectToType(Object o, Type type, JavaScriptSerializer serializer)
en System.Web.Script.Services.WebServiceMethodData.StrongTypeParameters(IDictionary`2 rawParams)
en System.Web.Script.Services.WebServiceMethodData.CallMethodFromRawParams(Object target, IDictionary`2 parameters)
en System.Web.Script.Services.RestHandler.InvokeMethod(HttpContext context, WebServiceMethodData methodData, IDictionary`2 rawParams)
en System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)
Is there any way to know the webmethod that raised the error?
I don't know what I'm making wrong.I have a submit button, and on click it should execute the funktion in the code behind, but I get the error that the funktion is undefined.this is my code in the .aspx webform:
<%@ Page Language="C#" AutoEventWireup="True" MasterPageFile="~/DashMaster.master" CodeBehind="BI_MDR.aspx.cs" Inherits ="BI_MDR.StoredProc"%> [code].......
I want to create a web method that accepts a List of custom objects (passed in via jQuery/JSON). When I run the website locally everything seems to work. jQuery and ASP.NET and everyone is happy. But when I put it on one of our servers it blows up. jQuery gets a 500 error after the ajax request with the response being:
System.InvalidOperationException: EditCustomObjects Web Service method name is not valid.
[WebMethod]
public void EditCustomObjects(int ID, List<CustomObject> CustomObjectList)
[code]...
I have seen 2 methods to handle error in project. One is using try catch in every method and another is using custom page and error log file .I know both method. Which one is the best method?
View 9 RepliesI have a DetailsView control about a store products.
When I hit the "Edit" button of the DetailsView control, I want to bind a DropDownList to list products categories and select the current product category in it.
I used the method "ModeChanged" to select the current product category like this:
[Code]....
the FindControl method DOES NOT find the "ddlCategory" (returns null) although it's present in the EditTemplateField.
I'm thinking to use "DropDownList's PreRender" event for doing the purpose I aim, but I want to know what is wrong!
How to solve this error? Error message is "BC30289: Statement cannot appear within a method body. End of method assumed.".
View 1 RepliesI have seen multiple posts related to my question but I was not able to resolve the issue. I am calling SP from C# class library and I need to check if returned XML is valid XML or not. When I run the SP in SQL management studio, I get XML. However, when I run the same SP from my c# code, I get null as return from SP. So I guess tried settings in design.dbml but to no avail.
Here is designer generated code.
[Function(Name="dbo.RequestXML")]
public ISingleResult< RequestXMLResult> RequestXML([Parameter(Name="RuleID", DbType="Int")] System.Nullable<int> ruleID)
{
[Code]....
As output, I get "MyCo.DBNAme.Database.Environment.RequestXMLResult"
How do I get the XML returned by SP?
I have jQuery plugin - progress bar. How to invoke server side method on success? The code is below:
(Everything works fine)
[Code]....