AllInWorld99 provides a reference manual covering many aspects of web programming, including technologies such as HTML, XHTML, CSS, XML, JavaScript, PHP, ASP, SQL,FLASH, jQuery, java, for loop, switch case, if, if else, for...of, for...in, for...each,while loop, blogger tips, blogger meta tag generator, blogger tricks, blogger pagination, client side script, html code editor, javascript editor with instant output, css editor, online html editor, materialize css tutorial, materialize css dropdown list,break, continue statement, label,array, json, get day and month dropdown list using c# code, CSS button,protect cd or pendrive from virus, cordova, android example, html and css to make android app, html code play,telerik show hide column, Transparent image convertor, copy to clipboard using javascript without using any swf file, simple animation using css, SQL etc. AllInWorld99 presents thousands of code examples (accompanied with source code) which can be copied/downloaded independantly. By using the online editor provided,readers can edit the examples and execute the code experimentally.


Store the objects in hidden Field and Retrieve from server side:-
      We can not store the objects in hidden field, but we can store using JSON.stringify to convertt the objects to string and store it to hidden field and access it from server side, but in server side we should need to serialize using JavaScriptSerializer and Deserialize.

Example:-
Client Side
var searchFilter = new Object();
searchFilter.ReportType = $('#<%=hdval.ClientID %>').val();
searchFilter.CompanyID = $("#<%=ddlCompany.ClientID%>").val();
searchFilter.CategoryID = $('#<%= HDtypeID.ClientID %>').val();
searchFilter.JobTitleID = jt;
searchFilter.Month = mnth;
searchFilter.Year = yar;
searchFilter.MonthCheck = $('#<%=HDmnthChk.ClientID %>').val();
searchFilter.FromDate = dt;
searchFilter.ToDate = dt1;
searchFilter.EmployeeID = EmpID;
searchFilter.ShiftID = shft;
searchFilter.DirectReportTo = rpto;

//Store the object values in hidden Field through string
var jsonSearchText = JSON.stringify(searchFilter);
$("#<%=hdnSearchFilter.ClientID %>").val(jsonSearchText);

Server Side
//Call the function and assign the value from objects
SearchFilter objSearch = new SearchFilter();
objSearch = GetSearchFilter();

objSearch.ReportType
objSearch.CompanyID
objSearch.CategoryID
objSearch.JobTitleID
objSearch.FromDate
objSearch.ToDate
objSearch.Monthcheck
objSearch.Month
objSearch.Year
objSearch.EmployeeID;
objSearch.ShiftID
objSearch.DirectReportTo

//Assign the value to class from hidden field converted object string
public class SearchFilter
{
    public string ReportType { set; get; }
    public int CompanyID { set; get; }
    public int CategoryID { set; get; }
    public int JobTitleID { set; get; }
    public string FromDate { set; get; }
    public string ToDate { set; get; }
    public int Monthcheck { set; get; }
    public int Month { set; get; }
    public int Year { set; get; }
    public int EmployeeID { set; get; }
    public int ShiftID { set; get; }
    public int DirectReportTo { set; get; } // 0 - Default  1-Show Direct Report
}

public SearchFilter GetSearchFilter()
{
    //Store the Hidden Filed value to str
    string str = hdnSearchFilter.Value;
    JavaScriptSerializer objSerilize = new JavaScriptSerializer();
    SearchFilter objRes= (SearchFilter) objSerilize.Deserialize(str, typeof(SearchFilter));
    return objRes;
}


Advertisement

Screen Shots:-
store objects to string

0 comments:

Post a Comment

Total Pageviews