Button click event is not fired - css

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.

Related

Moving childcontrol inside UserControl to placeholder in parent page

I have a custom popup panel in ASP.Net defined in the markup of a custom control (a context menu) and want to move it to a different placeholder which is placed in the parent (hosting) page.
The following code works, at least for the correct rendering.
protected override void OnInit(EventArgs e)
{
if (this.NamingContainer.NamingContainer.NamingContainer.FindControl("placeholder") is PlaceHolder placeholder)
{
placeholder.Controls.Add(popupPanel);
}
base.OnInit(e);
}
I now have the problem that events inside the popupPanel like OnClick() won't work. What do I have to do to get the event firing working?

attach two ASP.NET content page buttons to one masterpage event

I have one master page with two content page each content page has submit button:
<asp:ImageButton runat="server" type="image" id="buttonSubmit" name="buttonSubmit"
alt="ImageButton 1" src="images/button.png" OnClientClick="PreventExitPop=true"/>
I want to be able to create one onclick event on the masterpage.cs:
protected void buttonSubmit_Click(object sender, EventArgs e)
{
//
}
and attach the two buttons from the content pages to this event.
<asp:ImageButton runat="server" type="image" id="buttonSubmit" name="buttonSubmit"
alt="ImageButton 1" src="images/button.png"
onclick="buttonSubmit_Click"
OnClientClick="PreventExitPop=true"/>
The problem is that each content page knows only his code file and not the masterpage.cs.
You could write event handlers for each control and in those handlers you call a event handler method in the master page
protected void buttonSubmit_Click(object sender, EventArgs e)
{
((MasterType) this.Master).buttonSubmit_Click(sender, e);
}
i think you should not be able to do that,
and its not true that a event handler bind to two separate event at all...
i think, if you can, you should create your button on master page...
if you can not, you should have two event handler for these buttons, but u can create a method and in this method do everything you want, and call this method from two defined handlers...

asp.net dynamic user control button click issue

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.

How to implement paging in gridview in a modular popup?

I am using a modular popup to show gridview in a popup. Now I want to implement paging of this gridview. When I click on the page number the popup disappears. How do I avoid it? I want it to disappear only when clicking close button.
I assume that you're using the ModalPopupExtender from the AjaxControlToolkit.
If you're posting back you always need to call ModalPopupExtender1.Show() in codebehind when you want it to stay visible.
You could simplify it by using Page_PreRender if you have many events and you don't want to remember this always:
protected void Page_PreRender(object sender, System.EventArgs e)
{
// change "this" to somewhat appropriate for example your GridView
// "this" makes sense for example in a UserControl
if (this.Visible) {
this.ModalPopupExtender1.Show();
}
}

Refresh problem when treeview node changed

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.

Resources