Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
R

Ray Wampler

@Ray Wampler
About
Posts
5
Topics
0
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Javascript Replace
    R Ray Wampler

    The string object in JavaScript has a replace method, so if you need to do more than a simple replace then we'd need some details. From http://www.w3schools.com/jsref/jsref_replace.asp[^]: Syntax stringObject.replace(findstring,newstring) Parameter Description findstring Required. Specifies a string value to find. To perform a global search add a 'g' flag to this parameter and to perform a case-insensitive search add an 'i' flag newstring Required. Specifies the string to replace the found value from findstring If you need to simulate the .startsWith function in JavaScript then here's an article that demonstrates how to do so using regular expressions: http://www.tek-tips.com/faqs.cfm?fid=6620[^] If you need to do something different then let us know. Regards,

    Ray Wampler www.RayWampler.com

    ASP.NET javascript

  • Validating parameters and then passing as post parameter to another site
    R Ray Wampler

    If the 3rd-party site accepts variables in the query string then it's very straightforward:

        string \_a = "abc";
        string \_b = "def";
        string \_c = "ghi";
        string \_d = "jkl";
    
        string postToUrl = "http://www.RayWampler.com";
    
        Response.Redirect(postToUrl + "?\_a=" + \_a + "&\_b=" + \_b + "&\_c=" + \_c + "&\_d=" + \_d);
    

    If your values could contain special characters then you'll want to url encode them:

        string \_a = Server.UrlEncode("abc");
    

    If the 3rd-party site would only accept form POSTs then you'll need to use a technique like the one described in this article: Posting form data from ASP.NET page to another URL[^]

    Ray Wampler www.RayWampler.com

    ASP.NET question database help tutorial

  • senerio
    R Ray Wampler

    oops, I just realized the first function has one line that's incorrect. It should be:

    private DataTable ItemTable()
    {
    if (Session["tablevalues"] == null)
    {
    DataTable dt = new DataTable();
    dt.Columns.Add("Items");
    dt.Columns.Add("Price");
    Session["tablevalues"] = dt;
    }
    return Session["tablevalues"];

    } After your if statement then Session["tablevalues"] will exist. The code will either create it for the first time or will return what's currently stored there.

    ASP.NET question database

  • senerio
    R Ray Wampler

    Now that I see your code I think that I can suggest something that will work. You're already storing the data table in session, so you don't need an additional session variable your code can check for the existence of the data table in session. If I understand the issue correctly then what you want is the first time through to create the table and store it in session, and each subsequent time you want to add a new row to the existing table. First you create a helper function that returns a data table. This is where you check the session:

    private DataTable ItemTable()
    {
    if (Session["tablevalues"] == null)
    {
    DataTable dt = new DataTable();
    dt.Columns.Add("Items");
    dt.Columns.Add("Price");
    Session["tablevalues"] = dt;
    }
    return dt;
    }

    The above code will create the data table in session if it does not exist and then return it. It it already exists then it returns what's there. You now change your button handler as follows:

    foreach (GridViewRow row in GridView1.Rows)
    {
    CheckBox box1 = (CheckBox)row.FindControl("CheckBox1");
    if (box1.Checked)
    {
    DataTable dt = ItemTable();

      DataRow dr = dt.NewRow();
      string name1 = row.Cells\[2\].Text;
      double cost1 = Convert.ToDouble(row.Cells\[3\].Text);
      dr\["Items"\] = name1;
      dr\["Price"\] = cost1;
      dt.Rows.Add(dr);
      GridView2.DataSource = dt;
      GridView2.DataBind();
      cost = cost + cost1;
      Label12.Visible = true;
      Label12.Text = "Total Price " + cost ;
    
      Session\["tablevalues"\] = dt;
    

    }

    The line of code, DataTable dt = ItemTable(), is going to get either a new table or table with the rows you added. You then add your new row, update the grid, and store the table in session. I hope that's what you were looking for... Ray Wampler http://wwww.RayWampler.com

    ASP.NET question database

  • senerio
    R Ray Wampler

    If I understand your question correctly then I believe that a Session variable can help you. You page should have at least two event handlers, one for Page_Load and one for your button OnClick event. Page_Load always executes first. When the page first loads it goes through Page_Load with IsPostBack == false and When you click the button it first calls Page_Load with IsPostBack == true, then it executes your Button_Click event where you should have the code snippet that you only want to execute one time. Let's say here's your button click event handler: public void MyButton_OnClick(object sender, EventArgs args) { if (Session("MyButton_Handled") == null) { // Your one-time code snippet goes here // Set the session varaible Session("MyButton_Handled") = true; } } First time through the session variable will be undefined, which should return null. After you execute the code then the variable is defined and the one-time code gets skipped. Ray Wampler www.RayWampler.com

    ASP.NET question database
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups