I have an airline site in which i am trying to display the fare from different API/Web service. But Firstly i want to display the search page--> Display processing --> binding data in the page from theses API/web service as they received.
but i am not able to display search page before the result processing.
What i have tried (code)-
public partial class asyncgridview : System.Web.UI.Page,ICallbackEventHandler
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsCallback)
{
ltCallback.Text = ClientScript.GetCallbackEventReference(this, "'bindgrid'", "EndGetData", "'asyncgrid'", false);
}
}
private string _Callback;
public string GetCallbackResult()
{
return _Callback;
}
public void RaiseCallbackEvent(string eventArgument)
{
DataTable table = fetchData();
gvAsync.DataSource = table;
gvAsync.DataBind();
using (System.IO.StringWriter sw = new System.IO.StringWriter())
{
gvAsync.RenderControl(new HtmlTextWriter(sw));
_Callback = sw.ToString();
}
}
}
regards
Avishek
Related
protected void Page_Load(object sender, EventArgs e)
{
if (Session["namereturn"] != null)
{
MVOH.Text = Session["namereturn"].ToString();
}
protected void NextPage_Click(object sender, EventArgs e1)
{
Session["name"] = Convert.ToInt32(MVOH.Text);
Response.Redirect("~/Solution.aspx");
}
I am having the above code in first page and trying to pass value from textbox (MVOH) to next page. In the next page I have the code below. It works for the first value but it does not work if i want to change the value in first page and pass it to the next page second time..So I think I have to use count for the nextPage Button but I don't know how to use that and I want to display this value to the text box till i close the browser..Its like the checkout system in Ecommerce where you can go back and change your details..
protected void Page_Load(object sender, EventArgs e)
{
if (Session["name"] != null)
{
TextBox1.Text = Session["name"].ToString();
Session["namereturn"] = TextBox1.Text;
}
}
protected void Button_Click(object sender, EventArgs e1)
{
TextBox1.Text = Session["namereturn"].ToString();
Response.Redirect("~/Details.aspx");
}
What you should techinically do:
You should be submitting the information from textbox1 to a postback action related to page1.cshtml then redirect to the action that will render page2.cshtml and pass the textbox1 information
General Example below:
Public ActionResult Page1()
{
return View();
}
[HttpPost]
Public ActionResult Page1(ViewModel model)
{
return RedirectToAction("Page2",new{ textbox1 = model.textbox1});
}
Public ActionResult Page2(string textbox1)
{
var model = new ViewModel;
model.Textbox2 = textbox1;
return View(model);
}
Based on your question this is what you want:
If do not want to carry it back to the server, you could use the sessionStorage or localStorage from html5 to hold said information from page1.cshtml to page2.cshtml
Reference:
http://www.w3schools.com/Html/html5_webstorage.asp
drop-down list in C#.net not showing the items it supposed to show!
i hv a drop-down list that suppose to show image names from a folder, but it is not doing that!
i dont have errors when launching the .aspx file!
buuuuuut when i get output there is only empty dropdown list!
this the ManageProducts.aspx codes are:
Name:
Type:
" SelectCommand="SELECT * FROM [ProductTypes] ORDER BY [Name]">
Price:
Image:
Description:
and this the behind codes:
using System;
using System.Collections;
using System.IO;
public partial class PagesNew_ManagementPages_ManageProducts : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack) //this baby makes the data not come every time the pg is refreshed ,
//postback=refresh page
GetImages();
}
private void GetImages()
{
try
{
//get all filepaths
string[] images = Directory.GetFiles(Server.MapPath("~/Img/Products/"));
//get all filenames and put them in a stupid array....yeah DSA days
ArrayList imageList = new ArrayList();
foreach (string image in images)
{
string imageName = image.Substring(image.LastIndexOf(#"\", StringComparison.Ordinal) + 1);
imageList.Add(imageName);
// see the Array in dd viwe datasource and refresh
ddImage.AppendDataBoundItems = true;
ddImage.DataBind();
}
}
catch (Exception e)
{
lblResult.Text = e.ToString();
}
}
protected void ddImage_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
You want to bind your datalist outside of the for loop.
ArrayList imageList = new ArrayList();
foreach (string image in images)
{
string imageName = image.Substring(image.LastIndexOf(#"\", StringComparison.Ordinal) + 1);
imageList.Add(imageName);
}
ddImage.DataSource = imageList;
ddImage.AppendDataBoundItems = true;
ddImage.DataBind();
I am writing one class with the help of HTTPModule to check userIdentity in session before he access any page.If the variable in the session is null or empty i am redirecting the user in session expired page.
Code in Class:
public class SessionUserValidation : IHttpModule
{
public void Dispose()
{
}
public void Init(HttpApplication application)
{
application.PreRequestHandlerExecute += new
EventHandler(application_PreRequestHandlerExecute);
}
private void application_PreRequestHandlerExecute(object sender, EventArgs e)
{
HttpApplication application = (HttpApplication)sender;
IHttpHandler handler = application.Context.Handler;
Page reqPage = handler as Page;
if (reqPage != null)
{
reqPage.PreInit += new EventHandler(CustomModule_Init);
}
}
private void CustomModule_Init(object sender, EventArgs e)
{
Page Page = sender as Page;
if (!Page.Request.Url.ToString().Contains("mySessionExpired.aspx") &&
!Page.Request.Url.ToString().Contains("myLogin.aspx"))
{
if (HttpContext.Current.Session["encryptedUserId"] == null)
{
HttpContext.Current.Response.Redirect("../Modulenames/mySessionExpired.aspx", false);
}
}
}
}
everything is working fine , only issue is that its adding some kind of encryption in URL for which my Breadcrumbs are not working in the page. The url transforms like :
://thewebsite/Project/(S(jnd4o5ljdgs0vq1zd4niby4a))/Pages/mySessionExpired.aspx
no idea why this fragment of text has been added ... please help
--Attu
i was searching google for that is there any way to add any method in my page at run time. i got a link from stackoverflow for this....that is expando object.
i am not familiar with expando object. here is little snippet of code i got and like
namespace DynamicDemo
{
class ExpandoFun
{
public static void Main()
{
Console.WriteLine("Fun with Expandos...");
dynamic student = new ExpandoObject();
student.FirstName = "John";
student.LastName = "Doe";
student.Introduction=new Action(()=>
Console.WriteLine("Hello my name is {0} {1}",student.FirstName,student.LastName);
);
);
Console.WriteLine(student.FirstName);
student.Introduction();
}
}
}
according to my situation i need to add a routine below like
in many aspx page.
[WebMethod]
public static string LoadData(string CountryCode,int PageIndex)
{
string strData = "";
if (CountryCode != "")
{
strData = Left1.HavingCountry(CountryCode, PageIndex);
}
else
{
strData = Left1.WithoutCountry(PageIndex);
}
return strData;
}
so i need to know that is there any way to add some technique in my ascx page which will add the above method in all the aspx pages which host that particular ascx. please help me to achieve it. thanks
I don't think it is possible.
Can you do this way
1. create a `class` which extents `System.Web.UI.Page`.
2. write you `WebMethod` in that class.
3. Create your aspx pages by extending this class
public partial class _Default : TestUserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
public class TestUserControl : System.Web.UI.Page
{
[System.Web.Services.WebMethod]
public static string LoadData(string CountryCode, int PageIndex)
{
string strData = "";
if (CountryCode != "")
{
strData = Left1.HavingCountry(CountryCode, PageIndex);
}
else
{
strData = Left1.WithoutCountry(PageIndex);
}
return strData;
}
}
I am adding a user control dynamically on a page, the user control has a save button that takes data from both user control and page to save in the DB, in the same save method i want to access a method wrriten in the page, so i that mehod had code to rebind the grid kept in the page.
So how can i call a page method in the dynamically added user control?
I was going to suggest creating a base class for your pages, but found an even better way to accomplish this task:
http://www.codeproject.com/Articles/115008/Calling-Method-in-Parent-Page-from-User-Control
Control code:
public partial class CustomUserCtrl : System.Web.UI.UserControl
{
private System.Delegate _delWithParam;
public Delegate PageMethodWithParamRef
{
set { _delWithParam = value; }
}
private System.Delegate _delNoParam;
public Delegate PageMethodWithNoParamRef
{
set { _delNoParam = value; }
}
protected void Page_Load(object sender, EventArgs e)
{
}
protected void BtnMethodWithParam_Click(object sender, System.EventArgs e)
{
//Parameter to a method is being made ready
object[] obj = new object[1];
obj[0] = "Parameter Value" as object;
_delWithParam.DynamicInvoke(obj);
}
protected void BtnMethowWithoutParam_Click(object sender, System.EventArgs e)
{
//Invoke a method with no parameter
_delNoParam.DynamicInvoke();
}
}
Page code:
public partial class _Default : System.Web.UI.Page
{
delegate void DelMethodWithParam(string strParam);
delegate void DelMethodWithoutParam();
protected void Page_Load(object sender, EventArgs e)
{
DelMethodWithParam delParam = new DelMethodWithParam(MethodWithParam);
//Set method reference to a user control delegate
this.UserCtrl.PageMethodWithParamRef = delParam;
DelMethodWithoutParam delNoParam = new DelMethodWithoutParam(MethodWithNoParam);
//Set method reference to a user control delegate
this.UserCtrl.PageMethodWithNoParamRef = delNoParam;
}
private void MethodWithParam(string strParam)
{
Response.Write(“<br/>It has parameter: ” + strParam);
}
private void MethodWithNoParam()
{
Response.Write(“<br/>It has no parameter.”);
}
}