I have a Devexpress gridview with property enablecallbacks=false. When I open the editform and enter some data and click update, it loses the data entered but does the validation. How do I make the editform work retain the value?. I dont want the editform to lose the data during postback?. Any help?.
I have to have the edvexpress with this property to have another control inside the editform to work?.
You need to setup routing for your edit function in the Gridview settings;
settings.SettingsEditing.UpdateRowRouteValues = new { Controller = "Controller", Action = "Action" };
You also need to call this from some button for example from your editform Example;
#Html.DevExpress().Button(settings =>
{
settings.Name = "Name";
settings.Text = "DELETE";
settings.ClientSideEvents.Click = "function(s, e){ GridName.UpdateEdit(); }";
}).GetHtml()
However in your question it does not say in what framewoork you are woorking, provided examples are from MVC.
Related
I
have created 2 drop down list and 2 text boxes dynamically in asp.net .i disable text box at run time .i want that when i select item from drop down text box should be enable how to perform this task please help me :(
On SelectedIndexChanged on the dropDownList call a function that sets the textbox enabled = true. To access controls that have been dynamically added you can use FindControl as per C#, FindControl
I think something like this should help you:
In your page's OnInit event:
DropDownList ddl = new DropDownList();
ddl.SelectedIndexChanged += new EventHandler(ddl_SelectedIndexChanged);
placeholder.Controls.Add(ddl); //assuming this is what you use to dynamically show the dropdown list
TextBox yourTextbox = new TextBox(); //declare the variable outside to be able to be accessed by other methods, but it must be instantiated here. declaration here is for illustration purposes only
yourTextBox.Enabled = false;
placeholder.Controls.Add(yourTextBox);
Inside the instantiated event handler:
void ddl_SelectedIndexChanged(object sender, EventArgs e)
{
yourTextbox.Enabled = true;
}
I am working with the .Net List view along with a data pager to enable pagination for a list view.
I am able to set the pagination working perfectly for the list view but I wish to have a method being called when ever the user clicks on any of the page numbers in the data pager.
I want to perform some operation whenever the page number is called. I guess there is no onclick event, so is there any other way by which this is possible.
Thanks
you can set it as imagebutton or linkbutton.
I have piece of code.. you just need to implement it.
you can set link and click event.
foreach (DataPagerFieldItem dpfItem in dtpPaging.Controls)
{
foreach (Control cPagerControls in dpfItem.Controls)
{
if (cPagerControls is ImageButton)
{
ImageButton imgNavigation = cPagerControls as ImageButton;
imgNavigation.PostBackUrl = CommonLogic.GetFormattedURL(strPageUrl);
imgNavigation.Click += new ImageClickEventHandler(imgNavigation_Click);
}
if (cPagerControls is LinkButton)
{
LinkButton lnkNumbers = cPagerControls as LinkButton;
lnkNumbers.PostBackUrl = CommonLogic.GetFormattedURL(strPageUrl);
lnkNumbers.Click += new EventHandler(lnkNumbers_Click);
}
}
}
You can bind a handler to the OnPagePropertiesChanging Event of the List View. A PagePropertiesChangingEventArgs object is passed to the handler as argument which contains MaximumRows and StartRowIndex properties. You can use these to calculate the current page number. It is very easy and requires no code-behind event binding as the solution proposed by sikender.
I have a page that dynamic create a table of contacts, if the contact got an email I also create an image button with a click event.I have a similar function in the rest of the page that works perfectly. And I used this before without any problems:
protected void CreateContactsList(IQueryable<AA_BranschFinder.Login.vyWebKontaktpersoner> lContacts) // Creates a table in the aspx from an IQueryable List
{
if (1 == 1)
{
htmlTblContactsContent.Rows.Clear();
foreach (var p in lContacts)
{
HtmlTableRow tr = new HtmlTableRow();
HtmlTableCell tdName = new HtmlTableCell();
HtmlTableCell tdCompanyName = new HtmlTableCell();
HtmlTableCell tdEmailAdress = new HtmlTableCell();
tdName.InnerHtml = p.strFnamn + " " + p.strEnamn;
tdCompanyName.InnerHtml = p.strNamn;
//Displays an image if the contacts has an email
if (p.strEpost != null)
{
ImageButton imgEmail = new ImageButton();
imgEmail.CommandArgument = p.intKundID.ToString();
imgEmail.ImageUrl = "images/symbol_letter.gif";
imgEmail.CssClass = "letter";
imgEmail.Click +=new ImageClickEventHandler(imgEmail_Click);
tdEmailAdress.Controls.Add(imgEmail);
}
tr.Cells.Add(tdCompanyName);
tr.Cells.Add(tdEmailAdress);
tr.Cells.Add(tdName);
htmlTblContactsContent.Rows.Add(tr);
}
}
}
void imgEmail_Click(object sender, ImageClickEventArgs e)
{
Breakpoint here
throw new NotImplementedException();
}
The page is living inside a java popup window. But I have paging numbers with similar event creation that works fine. But they are Linkbuttons.
Where are you calling your Create method? You need to do it before the other event handlers run, ideally in the Page.Init. Otherwise, the data posted back to the page are indicated an event firing for a control that doesn't yet exist.
I would also make sure that you give your ImageButton an ID. It will make debugging a lot easier.
imgEmail.ID = String.Format("EmailImageButton_{0}", p.intKundID);
An alternative solution is to look at the __eventtarget and __eventargument parameters in the Request object and see which button was clicked there.
You'll have to create the dynamic controls on EVERY postback. Also check the code in the imgEmail_Click event handler; if you have created the event handler method using .NET IDE's Alt + Shift + F10 method, then there's a chance that you have not removed this line -
throw new Exception("The method or operation is not implemented.");
If I´m not misstaking the imagebutton is a submit kind of button while the linkbutton is an a-tag with javascript. Maybe changing your imagebutton click (ie usesubmitbehaviour set to false) will solve your problem.
Make sure the event handler is added on your postbacks. When adding it just on initial page load, the event won't be handled! (Just encountered and solved this problem myself.)
In PageLoad event of the form, I can not reference server side control within logged in template. What am I missing. So when I am logged in I will show text box control otherwise I will show text like "please login to do soso.."
Please help ..
you can use the FindControl method on your loginview control to get them...
TextBox t = (TextBox)LoginView2.FindControl("TextBox1");
string s = null;
if (t != null)
{
// textbox is in the current scope of the LoginView
s = t.text;
}
else
{
// the textbox is not in the current scope of the LoginView.
}
However, this will only work for the controls that are currently in the shown view of the LoginView control. You'd have to test that you're showing the logged in view before trying to grab the textbox, or you could also test that the FindControl doesn't return a null reference.
If you're still having trouble referencing the hidden object, you might not be entering the right value for it. Say you have a drop down list called "DropDownList1" nested inside a loggedInView. You have to set a new object that uses the FindControl method of the DropDownList class, and then use that NEW object:
DropDownList d = (DropDownList)ucLogin.FindControl("DropDownList1");
bool answer = d.SelectedValue.StartsWith("S");
if (answer == true)
{
Response.Redirect("~/MemberPages/ChangePassword.aspx");
}
In my case, I am redirecting the user to a new page if that objects selected value starts with an "S".
Works for me, and I hope it works for you!
Ben sewards
I'm currently trying to add a FilteredTextBoxExtender in a ASP.NET composite control, but I can't get it to work.
I have the following code within the overridden CreateChildControls method:
var textbox = new TextBox { ID = string.Format("{0}_textbox", ID);
var filteredTextBoxExtender = new FilteredTextBoxExtender { ID = string.Format("{0}_filter", ID), TargetControlID = textbox.ID, FilterType = FilterTypes.Numbers };
Controls.Add(textbox);
Controls.Add(filteredTextBoxExtender);
Somehow, it looks like it is added correctly when I view the source of my test page, but it won't fire the filtering
Sys.Application.add_init(function() {
$create(AjaxControlToolkit.FilteredTextBoxBehavior, {"FilterType":2,"id":"ctl00_testTextBox_testTextBox_filter"}, null, null, $get("ctl00_testTextBox_testTextBox_textBox"));
});
...
<input id="ctl00_testTextBox" name="ctl00$testTextBox$testTextBox_textBox" type="text" value="" id="ctl00_testTextBox_testTextBox_textBox" />
Any idea what goes on here, and how to get it to fire the filtering?
edit:
I've narrowed it down to a matter of dynamically choosing which controls to render. The FilteredTextBoxExtender works if I explicitely render each child control, but not if I don't render one of the child controls in the composite control (a label control)
Try this:
The problem is the textbox's id. If you check the generated JavaScript, you can sense, the input id is different from assigned id to $get("ctl00_testTextBox_testTextBox_textBox"). So your code doesn't work. You should mark your composite control by INamingContainer marker inerface. Thus, the composite control's id combines with the added textbox id and generates an unique identity. It resolves the problem.
public class Foo : CompositeControl
{
protected override void CreateChildControls()
{
var textbox = new TextBox { ID = "textbox" }
var filteredTextBoxExtender = new FilteredTextBoxExtender { TargetControlID = textbox.ID, FilterType = FilterTypes.Numbers };
Controls.Add(textbox);
Controls.Add(filteredTextBoxExtender);
}
}