I have a Treeview in a masterpage and a products page in child page.
When i click treeview node i want to bind data to a gridview on the product page.
protected void trvCategoryTab_SelectedNodeChanged(object sender, EventArgs e)
{
if (trvCategoryTab.SelectedNode.Value != string.Empty)
{
Response.Redirect("~/Customer/Products.aspx?Search=" + trvCategoryTab.SelectedNode.Value);
}
}
It's working fine, but the problem is that the page reloads every time. I want to prevent this.
Is there any other method to redirect to the child page?
It sounds like you want to use AJAX.
Related
I have a cart in master page that this cart is inside update panel.
In my content page I have a listview that in this listview exist linkbutton for add product to my cart.
I want to add product to cart using these linkbuttons without refresh, and cart is updated.
I have this code in my content page:
protected void Page_Init(object sender, EventArgs e)
{
UpdatePanel up = (this.Master.Master.FindControl("UpCart")) as UpdatePanel;
AsyncPostBackTrigger trigger = new AsyncPostBackTrigger();
trigger.ControlID = lvNewProducts.UniqueID;
trigger.EventName = "ItemCommand";
up.Triggers.Add(trigger);
}
But my page is refreshed when I click in link button.
Please help me!
Do you mean you want a partial post back and you are getting a full post back?
I think you can't add AsyncPostbackTriggers to an update panel from a different naming container. You did try with lvNewProducts.UniqueID to set ControlID, which is normally set with the ID. So that's a hint that this might be the case.
What you can do is calling RegisterAsyncPostBackControl on the ScriptManager.
Assuming your ScriptManager is in your master page and it's ID is myScriptManager you have todo the following:
protected void Page_Init(object sender, EventArgs e)
{
ScriptManager myScriptManager = (this.Master.Master.FindControl("myScriptManager")) as ScriptManager;
if (scriptManager != null) {
scriptManager.RegisterAsyncPostBackControl(lvNewProducts);
}
}
That replaced your code and should result in a partial post back. The link to your update panel to get updated is still missing, so you should do the following to get it updated in the ItemCommand event handler (e.g. if you set OnItemCommand="ListViewClicked":
protected void ListViewClicked(object sender, EventArgs args) {
//Do whatever necessary
//Now update your update panel
UpdatePanel up = (this.Master.Master.FindControl("UpCart")) as UpdatePanel;
if (up != null) {
up.Update();
}
}
Asp button click does not fire. I wrote Response.Write("404.aspx"); in to button click event in codebehind. But it does not fire. Here is the page with a fire problem button:
please click here
thanks.
Here is the code behind:
protected void bntTest_Click(object sender, EventArgs e)
{
Response.Redirect("404.aspx");
}
protected void btn2_Click(object sender, EventArgs e)
{
Response.Redirect("404.aspx");
}
It does not work because your submit button is not inside the form tag so it won't be able to post the submitted data and the same time, the click event will not fire as the page does not post, you can see below:
EDIT:
You have added a nested form tag that you can not because form tag can not be nested within another form tag. So just remove the nested form tag and it will work.
Try to restructure your project using these guidelines:
Only add form elements to aspx pages
Add main content to MasterPage from pages
Add any content that needs to be nested within a form to a UserControl that is placed within a page.
I added controls (i.e. template column) dynamically in grid view and click on button (post back) then grid view populated existing data (i.e.posted data) twice separated by
protected void Page_Init(object sender, EventArgs e)
{
//on init recreated controls
// if (IsPostBack)
{
gvFirst.DataSource = GetData("select top 10 * from Project_Master");
gvFirst.DataBind();
}
}
Sounds like you might be using Auto-generated fields. In design view, click the smart tag on the gridview and click "edit columns." Then uncheck the checkbox that says "Auto-generate fields." I think this should fix your problem if I am understanding you correctly.
I made researching about this subject I could not find proper answer.
In my default.aspx page, I have a treeview. Codes are in default.aspx like below:
protected void Page_Load(object sender, EventArgs e)
{
}
protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
{
Control ucont;
if (TreeView1.SelectedNode.Value == "Yeni Dönem")
{
ucont = LoadControl("usercontrols/yenidonem.ascx");
PlaceHolder1.Controls.Add(ucont);
}
else
{
ucont = LoadControl("usercontrols/tabloktar.ascx");
PlaceHolder1.Controls.Add(ucont);
}
}
I load user controls dnynmicaly. User controls are have button control. I can not fire user control's button click when I load it dynamcally. How can I solve this ?
Thanks.
First of all, I would not recommend adding control dynamically later than in Page_Load event. Other things to remember is that You should add it on each page load and assign unique ID value the control that does not change between postbacks.
In this case, the easiest way would be to always add both controls to the page and show appropriate one using Visibility property.
If that's not suitable for You, try to move the code from TreeView1_SelectedNodeChanged to the Page_Load event and load appropriate control on each postback until it should be changed to another one.
I haven't tested this, so if You have any issues when using thise answer, let me know in the comments and I'll try to help.
I am using Asp.Net Dynamic Data. I want to remove delete button from List and details page. I dont want to remove it from mark up. Is there any way to remove delete button based on entity and without adding custom pages?
Hi I was able to do it with this code.
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton delete = (LinkButton) e.Row.FindControl("DeleteLinkButton");
delete.Visible = false;
}
}
Try Creating a custom page and you will have all control over default pages template. Look following video explains how to do it.
http://www.asp.net/web-forms/videos/aspnet-dynamic-data/how-do-i-make-custom-pages