I am creating a user control where in i have different HTML text boxes and for items like name profession contact etc.
i have a edit and save button for each item. so when i click on the save button i want the value of that text box and update the same in the database . So for this i want to send that value to the ASPX page. but i don't know how to send that value to the ASPX.Also if there is another way to achieve this them please suggest.I am using the three tier architecture.
Thankx
If text box is asp text box or html runat="server" st than you need to expose textbox value as property
public string textData
{
get { return mytextbox.Text; }
set { mytextbox.Text = value; }
}
OR
If you text box is html than make use of Request.QueryString["textboxnameorid"] will provide you data on postback.
if you are using asp.net textbox, you can create public properties in you usercontrol like this
public string Name
{
get { return tbName.Text; }
set { tbName.Text = value; }
}
and this public property can be get set in asp.net page easily..
Regards.
Related
I am unable to grab the value of a binding value in a label in Xamarin forms view. I want to me able to manipulate the label text then display it back to the view. Currently an API is providing the initial value of the EventCode variable and displaying it directly to the view. I want modify the EventCode variable value before its displayed to the view.
View:
Label x:Name="myLabel" Text={"Binding EventCode}"
C# behind code:
string x = Label.mylabel.text;
///////
Class:
public class EventSummary
{
public string EventCode {get; set}
}
mylabel.SetBinding(Label.TextProperty, new Binding("EventCode"));
You can store the mylabel text into string by following way.
string str = mylabel.GetValue(Label.TextProperty).ToString();
In my WinForm application when I want to add a row in xtragrid, I have a problem with getting the current value of the focused textbox.
Assume I have a textBox bind to Model.VchType.Title , Before I click Save button my focus is on txtTitle and I typed "title1" on it.
This is my code for Save button event:
Model.VchType row = xtraGrd.GetRow(xtraGrd.FocusedRowHandle) as Model.VchType;
I get null for row.Title after it hits the break point in this line of code.
And this problem only occurs when right before I click on save button focus is on txtTitle.
-------- UPDATE ------------
Here is some of code of model:
[System.ComponentModel.DataAnnotations.Schema.Table("vwVchType", Schema = "Sle")]
[Serializable]
public class VchType : Entity
{
private int _ID;
[System.ComponentModel.DataAnnotations.Schema.Column]
[RnDisplayName(typeof(Rnw.Sle.Properties.Resources), "ID")]
public override int ID
{
get
{
return _ID;
}
set
{
_ID = value;
}
}
private string _Title;
[System.ComponentModel.DataAnnotations.Schema.Column]
[RnDisplayName(typeof(Rnw.Sle.Properties.Resources), "Title")]
public string Title
{
get
{
return _Title;
}
set
{
_Title = value;
}
}
}
Also I created columns by designer.
I fill a bindingSource and set the property of the datasource of grid to this bindingsource in designer.
And I don't think problem is column name , because if before I click save button I focus on another controller, It works fine and I get value for row.Title.
You need to call
((GridView)xtraGrid.FocusedView).PostEditor();
or
gridView.PostEditor()this will save the current value to the editor EditValue.
Then you need to call view.UpdateCurrentRow() to validate the focused row and save its values to the data source.
So you need something like this
((GridView)xtraGrid.FocusedView).PostEditor();
((GridView)xtraGrid.FocusedView).UpdateCurrentRow();
Model.VchType row = xtraGrd.GetRow(xtraGrd.FocusedRowHandle) as Model.VchType;
You can focus another forms object before you save your data. So call:
anyControl.Select();
Before you save. This will close the open editor from your Textbox and post the changes to your DataSource. Normally this should be done by PostEditor(); which sometimes seems to lack.
I create a user control and add a textbox to it. In my windows form I add the user control i created and add a textbox and a button. How to copy the text I input from the textbox of Form to textbox of Usercontrol and vice versa. Something like
usercontrol.textBox1.text = textBox1.text
You could add to your User Control code a public property that delegates into the TextBox's Text property:
public string MyTxtBoxValue { get { return this.txtBox.Text; } }
And you could also have a setter to that, of course, if needed.
What you don't want to do, however, is exposing the whole TextBox by making it public. That is flawed.
From Form to Usercontrol
Form Code
public string ID
{
get { return textBox1.Text; }
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
userControl11.ID = ID;
}
Usercontrol Code
public string ID
{
set { textBox1.Text = value; }
}
There are multiple ways to access your user control text box data. One way to accomplish this would be to expose the text box on the user control at a scope that can be accessed via the form it's loaded on. Another way would be raising an event on the button click of the user control and subscribing to it on the parent form.
Although some stuff are inherited when creating a custom user control, for the most part you have to define your own properties. (like text value, etc..)
I would take a look at this:
http://msdn.microsoft.com/en-us/library/6hws6h2t.aspx
good luck!
I'm not too familiar with .NET, but I want to save a simple value (a number between 1 and 1000, which is the height of a particular div) to the viewstate and retrieve it when the update panel reloads (either in the markup somewhere or with javascript). What is the simplest way to do this?
This page gives me the following code:
string strColor;
if (Page.IsPostBack)
{
// Retrieve and display the property value.
strColor = (string)ViewState["color"];
Response.Write(strColor);
}
else
// Save the property value.
ViewState["color"] = "yellow";
However, I'm not totally clear on where or how to access the example strColor.
Since this is in the code behind, where will Response.Write even spit that code out? I couldn't find it when I tried this code. And how do I use javascript to set that value, instead of setting it in the code behind?
You can simply set the div as a server control as so:
<div id="yourdiv" runat="server" ...
And when the page posts back; simply set it's height by setting its attributes; for example:
yourDiv.Attributes("style","height:"+height_read_from_ViewState+"px;");
Or, you can store the height on the client side, using a Hidden field and reading that hidden field's value on the server side to set the div's height.
<asp:hiddenfield id="hdnHeight" runat="server" />
You set the height in Javascript as so:
function setHeight(value)
{
document.getElementById('<%=hdnHeight.ClientID').value=value;
}
And on post back on server side:
yourDiv.Attributes("style","height:"+hdnHeight.Value+"px;");
I would change strColor to a property and use the viewstate as a backing store for the propery.
public string strColor
{
get
{
return ViewState["strColor"];
}
set
{
ViewState["strColor"] = value;
}
}
And then you would use it like any other property:
if (Page.IsPostBack)
{
// Retrieve and display the property value.
Response.Write(strColor);
}
else
// Save the property value.
strColor = "yellow";
I created user control for textbox with autocompleteextender, and its working fine, but now i wanted to expose methods in user control to aspx page as a one of the property in user control,like in button control having onClientClick event.
and forgive my English.
Try adding a property like this to your user control:
public string OnClientClick
{
get { return Button1.OnClientClick; }
set
{
Button1.OnClientClick = value;
}
}