Loading data into a textbox and then changing it - html

i have made a textbox that gets it's text from a variable linked to a database.
ee from class employee and s from class general both work, and the data inside ee is correct.
when the page loads, the textbox does show the data inside ee.Field but when i change it and click save it doesnt change and doesnt save the new data in my database , i know for sure the the functions.fieldChange() works and that for some reason it doesnt get into the if(field.text!=ee.Field) (i have checked it using a simple label text change).
here is my html:
<asp:TextBox ID="field" runat="server"></asp:TextBox><br />
<asp:Button ID="Save" runat="server" Text="Save" OnClick="saveChanges" />
my asp.net:
string User;
Genral s = new Genral ();
public Employee ee;
protected void Page_Load(object sender, EventArgs e)
{
User = Session["User"].ToString();
ee = s.getEmployee(User);
this.field.Text = ee.Field;
}
protected void saveChanges(object sender, EventArgs e)
{
if (field.Text != ee.Field)
{
s.fieldChange(User, field.Text);
}
}
What doesnt it work? Thanks for the help

You need to check ispostback property in page load, when you hit save button it first called postback so it replace the value with the old one and your newly inserted data lost.
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
User = Session["User"].ToString();
ee = s.getEmployee(User);
this.field.Text = ee.Field;
}
}

Related

ASPNet Dropdown List from 0 to quantity available

I'm creating a webform for a Class assignment that essentially allows you to select a quantity from 0 to the amount available for each product. We're using AdventureWorks 2014 as our datasource.
However it only displays the maximum quantity and not from 0 to the max quantity.
I'm just stuck on what to add so it can display 0 to max quantity. Thanks.
I don't have anything in regards to the code behind, it's just the basic:
public partial class _Default : Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnOrder_Click(object sender, EventArgs e)
{
}
protected void ddlQuantity_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
You can perform binding by handling SelectedIndexChanged event from ddlProductName to fill ddlQuantity items:
ASPX
<asp:DropDownList ID="ddlProductName" runat="server" AutoPostBack="True" DataSourceID="ddlProductNameitems" DataTextField="Name" DataValueField="Name"
OnSelectedIndexChanged="ddlProductName_SelectedIndexChanged">
</asp:DropDownList>
<asp:DropDownList ID="ddlQuantity" runat="server" AutoPostBack="True" ...></asp:DropDownList>
Then use a List collection to store all numbers from 0 to maximum value set by SUM query then bind that List to DropDownList in SelectedIndexChanged event given above:
ASPX.cs (code-behind)
protected void ddlProductName_SelectedIndexChanged(object sender, EventArgs e)
{
List<string> quantities = new List<string>();
int maxQuantity = 0;
// retrieve SUM result from SqlDataSource
// if 'DataSourceSelectArguments.Empty' doesn't work, try other 'DataSourceSelectArguments' options
DataView view = QuantityChoices.Select(DataSourceSelectArguments.Empty) as DataView;
// set maximum quantity from SUM query result
if (view != null)
{
maxQuantity = int.Parse(view.Table.Rows[0]["TotalInventory"].ToString());
}
else
{
// assign maxQuantity from SqlConnection here
}
// add every quantity amount to the list...
for (int i = 0; i <= maxQuantity; i++)
{
quantities.Add(i.ToString());
}
// ... then sort from least value...
quantities.Sort();
// ... and bind the list here!
ddlQuantity.DataSource = quantities;
ddlQuantity.DataBind();
}
NB: System.Data namespace should be added to use DataView component. Note that it may necessary to remove DataSourceID, DataTextField & DataValueField from ddlQuantity to bind corresponding DropDownList with generated list of quantities.

I am unable to retrieve column value in a Telerik radgrid.

I am trying to select a column value in a selected row but I am unable to select the row. It seems that after clicking on the row to be selected, it does not go into the if statement. If I change the if statement to (dataItem.Selected = true) with only one "=", it goes in but returns the invoice id for all of the rows. Any advice on how to resolve this issue?
protected void RadGrid1_SelectedIndexChanged(object sender, EventArgs e)
{
var a ="";
foreach (GridDataItem dataItem in RadGrid1.MasterTableView.Items)
{
if (dataItem.Selected == true)
{
a = dataItem.GetDataKeyValue("InvoiceId").ToString();
Response.Write(a);
}
}
}
Do you allow multiple selections or only just single selection in your RadGrid?
To me, the foreach loop code block doesn't seem correct if you do single row selection.
protected void RadGrid1_SelectedIndexChanged(object sender, EventArgs e)
{
// get selected row
GridDataItem item =(GridDataItem)RadGrid1.SelectedItems[0];
}
Also, another point is you should set EnablePostBackOnRowClick property to true so that RadGrid's SelectedIndexChanged event will be fired properly on the server side.
<ClientSettings Selecting-AllowRowSelect="true" EnablePostBackOnRowClick="true">
</ClientSettings>
But if you wish to fire row select command from client side, then you should add a row click event with JS.
function RowClick(sender, eventArgs) {
sender.get_masterTableView().fireCommand("Select", eventArgs.get_itemIndexHierarchical());
}
Then associate that JS function to <ClientEvents OnRowClick="RowClick" /> in your aspx.
You can use RadGrid1.SelectedItems[0] To get your selected item.
protected void RadGrid1_ItemChanged(object sender, EventArgs e)
{
var myDataItem = RadGrid1.SelectedItems[0] as GridDataItem;
if (myDataItem != null)
{
var name = myDataItem ["InvoiceId"].Text;
}
}
And Woodykiddy is right. Check your postback and your allow row selecting.
And if you re using ajax dont forget the rad Ajax manager and panel.

ASP.NET iFrame Response.Redirect Parent Window

Is it possible to perform a response.redirect within an iFrame to redirect the whole page so that the destination page is viewable full screen and not contained within the iFrame?
Below is the current code behind
public partial class ServerResult : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
Any help would be much appreciated :-)
No.
Response.Redirect is a server command which sends (302 ?) header tells the client to redirect.
you are in the iframe world. you can't tell the server: "Hey , when you send me data - send it to the parent Iframe"
BUT What you can do , is this :
protected void Page_Load(object sender, EventArgs e) {
ClientScriptManager.RegisterClientScriptBlock(this.GetType(),
"aaa", "window.parent.location = 'http://yoursite.com'", true);
}
but you have to remove response.redirect from server.
Edit
var page = HttpContext.Current.Handler as Page;
if (page != null) page.ClientScript .RegisterClientScriptBlock(typeof(string), "Redirect", "window.parent.location='" + url + "';", true);

Navigate to the same View. Why Loaded and OnNavigatedTo events aren't called?

Im doing a cloud App(like Skydrive) in Windows Phone 8 , each time I navigate to a different folder I need to reload the FolderView.xaml page to display the content of this folder and I need to add the view to the back stack then I will be able to back to the previous path...
From now when I try to reload the FolderView from the FolderView.xaml.cs page, none event is called...
I don't understand why ? And if you have a solution you are welcome ...
private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
if (App.ElementSelected != null)
{
BdeskElement FolderChoosen = new BdeskElement();
FolderChoosen = App.ElementSelected;
Gridentete.DataContext = FolderChoosen;
GetFiles(FolderChoosen);
}
}
private async void llsElements_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
LongListSelector llselement = null;
listElementCollection.Clear();
if (sender != null)
llselement =(LongListSelector)sender;
if(llselement.SelectedItem!=null)
{
BdeskElement bdelement=(BdeskElement)llselement.SelectedItem;
if (bdelement.TypeElement==BdeskElement.BdeskTypeElement.Folder)
{
App.DocLibSelected = null;
App.ElementSelected = bdelement;
// I navigate to the same view here but nothing happens
NavigationService.Navigate(new Uri("/Views/BDocs/FolderView.xaml", UriKind.RelativeOrAbsolute));
}
}
}
To navigate to the same page with a new instance, you must change the Uri. For example:
NavigationService.Navigate(new Uri(String.Format("/Views/BDocs/FolderView.xaml?id={0}", Guid.NewGuid().ToString()), UriKind.Relative));
You can discard that parameter if you don't want/use it.

how to extract html code for website using iframe and silverlight

I need to load a specific webpage from a site that has multiple images on the site. I need to extract these images but I can't do this manually because the names of each image have no pattern and there will be hundreds of sites. I have a silverlight application to load the webpage in an iframe and I intended on extracting the html for this webpage and then retrieving the image source for each image from the extracted code and then populating a listbox.
I can load the web page in iframe with no problem, but I don't know how to retrieve the html code for the webpage.
public Page()
{
InitializeComponent();
System.Windows.Browser.HtmlElement myFrame = System.Windows.Browser.HtmlPage.Document.GetElementById("ifHtmlContent");
if (myFrame != null)
{
myFrame.SetStyleAttribute("width", "1024");
myFrame.SetStyleAttribute("height", "768");
myFrame.SetAttribute("src", txtURI.Text);
myFrame.SetStyleAttribute("left", "0");
myFrame.SetStyleAttribute("top", "50");
myFrame.SetStyleAttribute("visibility", "visible");
}
}
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
this.Button_Click(sender, e);
}
private void Button_Click(object sender, RoutedEventArgs e)
{
System.Windows.Browser.HtmlElement myFrame = System.Windows.Browser.HtmlPage.Document.GetElementById("ifHtmlContent");
if (myFrame != null) myFrame.SetAttribute("src", txtURI.Text);
}
private void txtURI_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
this.Button_Click(sender, e);
}
The following article may offer some help:
http://jesseliberty.com/2010/05/03/screen-scraping-when-all-you-have-is-a-hammer/