1
Answer

save files in local storage

hey team,
 
I just added two text boxes which is in a read only thing.Beside the textboxex i have kept the buttons called browse which shall be useful to browse a file from the directory and display it in a text box. Also i have kept a generate button which should again save the displayed files in the local storage but i could not proceed with it. Do solve my issue in a detailed manner.
 
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
//using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace gui_1
{
public partial class form1 : Form
{
public form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.InitialDirectory = "c:\\";
openFileDialog1.Filter = "xlsx files (*.xlsx)|*.xlsx";
openFileDialog1.FilterIndex = 2;
openFileDialog1.RestoreDirectory = true;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
string text = openFileDialog1.SafeFileName;
if (text == "Book1.xlsx")
{
tb_1.Text = openFileDialog1.FileName;
}
else
{
MessageBox.Show("Invalid file name");
tb_1.Clear();
}
}
}
private void label1_Click(object sender, EventArgs e)
{
}
private void fn_l2_Click(object sender, EventArgs e)
{
}
public static void SaveData(object obj, string filename)
{
}
private void browse_b2_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.InitialDirectory = "c:\\";
openFileDialog1.Filter = "xlsx files (*.xlsx)|*.xlsx";
openFileDialog1.FilterIndex = 2;
openFileDialog1.RestoreDirectory = true;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
string text = openFileDialog1.SafeFileName;
if (text == "Book2.xlsx")
{
tb_2.Text = openFileDialog1.FileName;
}
else
{
MessageBox.Show("Invalid file name");
tb_2.Clear();
}
}
}
private void tb_1_TextChanged(object sender, EventArgs e)
{
}
private void cancel_b1_Click(object sender, EventArgs e)
{
this.Close();
}
private void reset_b1_Click(object sender, EventArgs e)
{
Utilities.ResetAllControls(this);
}
public class Utilities
{
public static void ResetAllControls(Control form)
{
foreach (Control control in form.Controls)
{
if (control is TextBox)
{
TextBox textBox = (TextBox)control;
textBox.Text = null;
}
}
}
}
private void generate_b1_Click(object sender, EventArgs e)
{
if (tb_1.Text == "")
MessageBox.Show("Fields are empty!!");
if (tb_2.Text == "")
MessageBox.Show("Fields are empty!!");
}
}
}
Answers (1)
1
Smit Thakur

Smit Thakur

NA 72 2 7y
Try this:
 
foreach (var item in storeItem)
{
<input type="button" id="btn" value="@item.StoreItemName" onclick="addvalue($(this))" />
}
<script>
function addvalue(e) {
$('#ItemName').val(e.val())
}
</script>
0
Midhun T P

Midhun T P

NA 19.7k 281.1k 7y
Hi,
 
Please try like below -
 
<input type="button" id="btn" value="@item.StoreItemName" onclick="addvalue(this.value)" /> 
 
script -
 
function addvalue(myval) {
$('#ItemName').val(myval);
}
 
 The error in your question is not from the script you provided. It was coming from some other script. 
0
Shakil Ahmed

Shakil Ahmed

NA 49 1.2k 7y
@if (TempData["srResult"] != null)
{
List<StoreItem> storeItem = (List<StoreItem>)TempData["srResult"];
foreach (var item in storeItem)
{
<input type="button" id="btn" value="@item.StoreItemName" onclick="addvalue()" />
}
}
0
Ankit Sharma

Ankit Sharma

NA 8.8k 140.9k 7y
Hi,
 
Please post you whole Jquery code as  error is with "toLowerCase" method and that code snippet is not present in this screenshot.
 
Please refer 
 
https://stackoverflow.com/questions/23723005/uncaught-typeerror-cannot-read-property-tolowercase-of-undefined 
 
https://teamtreehouse.com/community/uncaught-typeerror-cannot-read-property-tolowercase-of-undefined