On details view, I would like to hide the new button.
On page load I have successfully done so by the following code:
dtvwMyProfile.Rows[5].Cells[0].Controls[2].Visible = false;
But how do I hide the New button when I hit cancel or update button after I am done editing.
The New button keeps showing up. How do I hide it completely from the screen.
In some event, the visible property keeps changing to true and how do i find out that event?
I want to be able to do it at run time instead of design time.
Dynamically changing the properties of child controls created by the DetailsView is not recommended.
If the button is being created by the DetailsView itself then all you need to do is set AutoGenerateInsertButton to false and you can do that in Page_Load.
I do not recommend randomly selecting a page event and handling it. If you do that then chances are it will just break again when you change something else.
Maybe try to do that in the ModeChanged event handler, which fires after the mode changes... But can you ensure new is always at position 2? You may want to verify the button by its text or command name.
Related
I have a page which is having the following
Some ddl's for Filter the data
A Submit button
A export Button
A GridView
In general We show/hide Export button if submit query results more than zero rows/ no rows
NOTE:
It is not only the case for one button but there would be more and i will have to check for the permission for every where i show /hide the buttons
For Example
Page_Load
showHideAsPerPermission(btnExport);
BtnSubmitClick()
if rows>0
btnExport.Visible = true;
else
btnExport.Visible = false;
But for the purpose of Permission
I want to set Export button visibility to true/false after BtnSubmit_click (or all controls events like selected index change, textChanged etc.) event has fired
A little Explanation of my problem
Say if you have permission to export then it only visible when rows>0 and if you don't have then it invisible even rows>0 but if i set the permission on page load and then i set exports visibility true for rows > 0 then it is visible even you don't have permission so is there any event which fires after control events
Is there any method which i can utilize for this purpose
I have read the following events and tried Page_Unload event which actually does nothing cause page is already rendered
So is there any method which could accomplish my task
Note:
As per my Knowledge there is no such Event so can i create a custom page event?
Just do it in Page_Load.
Keep in mind, on BtnSubmit_click, the page will post back, Page_Load is going to execute again (so you'll probably need something like if (!IsPostback)...), and then BtnSubmit_click.
I have the following scenario:
UserControlA contains a <asp:Button id="bSomeid" onClick="AddItem" /> with some code to an item to a shopping basket in AddItem.
UserControlB contains some LinkButton's that dynamically add a selection of UserControlA to the page in the OnClick event.
This is all done in an UpdatePanel. It is a little more complicated but I have pruned the information to what I believe is causing the problem, I will add more information if necessary.
The problem I have is that it takes 2 clicks for the AddItem event to trigger after I have added the items to the page after clicking the LinkButton.
I understand why this is happening - it is to late in the page cycle to register events for the next post back in the onclick - but can anyone think of a way around this? Can I force an event to be triggered on the next postback? I have tried to think of a way to run my code in page_load but I requuire access to the sender in the onClick.
Using .NET 4.0.
EDIT
I managed to find a way to get the link button sending the request in the Page_Load (using Request.Form["__EVENTTARGET"];) so I moved my code to the Page_load event. It still requires 2 clicks so I am assuming it isn't something to do with the onClick being registered to late.
Are there any other general things to check that could cause a button to require 2 clicks to post an event properly?
If your suspicion about being late in page life cycle is true then you can try using ScriptManager.RegisterAsyncPostBackControl method to register dynamically added controls in the link button click - considering that your button is within user control, you need to add public method into UserControlA that would actually register the button bSomeid1 and link button click from UserControlB would actually call the A control's method.
EDIT :
Another cause for button click not happening can be that button being dynamic control is not added in the page hierarchy when post-back happens (or it gets added very late in the page life cycle when the post back data is already processed). A really full-proof solution should add dynamic controls back to the page hierarchy in page_load it-self (and strictly maintaining same controls ids within hierarchy). If that's not possible then you can sniff the request (Request.Form) to detect the post-back.
In your case, you should ascertain if the button is indeed causing the post-back on each click. If yes, what is the POST data (Request.Form) for the first request - what is the __EVENTTARGET value on the first click (and post-back)? That should start your trouble-shooting.
On the other hand, a simple work-around could be to use html anchor element (you can still use link button) and have a javascript handler in the click event that would set some hidden variable and then submit the form (you can simulate the click on hidden button to trigger ASP.NET client side submit pipeline) . Now the hidden variable value can be used on the post-back to determine which link button has been clicked.
"Are there any other general things to check that could cause a button to require 2 clicks to post an event properly?"
Does it require two clicks on the control, or does it take accept a single click elsewhere on the screen, and then fire first time with a single click on the control?
I have my own (similar) issue with the Updatepanel where the first (expected) trigger does not fire and it seems that a single click elsewhere, and then the subsequent triggers fires first time (which totals 2 clicks)
[edit] Since you are working on this ATM, it may help me as well. Do you have a textbox with a trigger event on it? I do, and if I leave this blank (so that it does not fire) then there is no need for a second click.
I had a page with 3 update panels... based on textbox changes in updatepanel1, updates the modes of other panels before they click the submit button.
The problem is I created onblur events for the textboxes...once there is a postback everything works fine. But there is one worst case scenario where the user changes the textbox and uses the mouse scroll bar and clicks the submit button. In this case (as onblur event never occurs) I could not able to update the second and third update panels.
One solution I thought was, onclicking the submit button, I was trying to check the previous mode but this will not be possible for my case because of the design issues
You could always attach a Javascript event to the scrollbar to trigger the update as well.
Pseudocode:
window.onscroll:
if contents of textbox have changed:
do postback
else
do nothing
i have created Array of Linkbutton
and when user click on link button it will create an array of Radio Buttons
but it requires Postback all time so page load takes more time...
what is solution of it??
Use asp.net Ajax update panel.
Put link buttons and panel/view (or what ever control you are using ) update panel.
I am not sure if I am following a 100% but if you don't want to do a post back then your going to need to write some javascript(or use a framework like jquery) to generate radio buttons when the user clicks the link button(plus you probably don't want to use a link button then as it will try to always cause a postback or you will need to stop the post back from happening).
I search for results, click one, it opens in a new window, then edit it, and close the popup.
Then I hit 'search' to refresh my gridview, but the changes do not reflect unless I hit F5. It's caching it and I need to stop it, but I don't know how. IdeaS?
Are you rebinding the grid when the user clicks 'search'? You need to be sure that somewhere in the 'search' method control flow, you're doing this:
dataGrid.DataSource = updatedDataSource;
dataGrid.DataBind();
I'm guessing you're binding your results to the grid during PageLoad. Because the event handler for your search button gets fired after PageLoad, the new search results don't get bound to the grid until the next page request. If this is the problem you'll need to rebind the grid when handling the search button event.