How can I replace the reportviewer's refresh button? - report-viewer2010

I have a requirement to hide the refresh button on the reportviewer toolbar and replace it's functionality with a standard text display button on an ASP.net web form.
I know how set the ShowRefreshButton property to false to hide the embedded button, but I can't figure out what code I need behind my new asp button. I tried the following but it didn't work.
With ReportViewer1
.DataBind()
End With

Try this:
Me.ReportViewer1.LocalReport.SetParameters( _
New Microsoft.Reporting.WebForms.ReportParameter("Year", ddlYear.SelectedValue, False))
It did the trick for me, setting the parameter or parameters seems to rebind the control.

Related

Change value and text of button

I have a textbox and a button with an onClick event connected to it, and when the button is clicked once I want to change the text of the button and clear the textbox. How can i accomplish this?
If you want to do this on a postback (a complete refresh of the page), simply put code in your button click handler to set these values. For example, textbox.Text = string.Empty;
If you want to set it on the client side (without refreshing the page), then you'd need to use client script such as JavaScript.
This needs you to know about TextBox and its properties. Normally the value of a textbox you use its Text property as TextBox1.Text. In your case you put this statement in the button's click event
string txtValue=TextBox1.Text;
TextBox1.Text=string.Empty;
To see how to use TextBox and its properties. This can help

vs2008 web express: detailsview can not hide new button

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.

LinkButton alternative? (Need it to function like a normal link)

LinkButtons are giving me headaches. I thought, foolishly, that they allowed you to create programmatic links. Obviously this is not the case (by design), as they have behave nothing like normal links - you can't see your address when you hover over them, you can't open them in a new tab, etc.
Is there an alternative in .NET that actually lets you programmatically create a true HTML link? The ability to open multiple items in tabs is sort of a requirement. I've looked into styling a Button to look like a link, but it still behaves like a button, so this won't work either. Any ideas?
EDIT: Sorry, forgot: can't use HyperLink, as I need the ability to send CommandArguments, set OnClick events, etc. It needs to function as a button still.
The HyperLink control.
Set the href using the NavigateUrl property, and tagets (for new windows/tabs) can be set using the Target property
Edit to respond to question edit
I'm not really sure what you're after - your question is asking for a control that "functions like a normal link", so that clicking on it can open in a new window/tab, but your edit says you want to be submitting CommandArguments and using the OnClick event - so not a normal link.
The problem you've got here is that the PostBack processing of command arguments and OnClick events happens at the server, but the "open in a new window" happens on the client (using the "target" attribute of the anchor tag, or possibly with JavaScript) - these two don't really mix all that well.
A couple of options spring to mind:
Use a LinkButton, and if you handle a PostBack, output some JavaScript to open the new page in a new window.
Use a HyperLink control with a target and set the "CommandArguments" as a querystring element to the link - you can then process that on the catching page that opens in the new tab.
You can also cause JavaScript to fire onClick using the Attributes collection:
// Create a hyperlink
HyperLink link = new HyperLink();
link.NavigateUrl = "/somepage.aspx?arg=First";
link.Target = "_blank"; // Open in a new window
// Add a client side onClick event calling someMethod function with a reference
// to the link, and making sure the link processing stops.
link.Attributes.Add("onClick", "someMethod(this);return false");
You mean HyperLink?
Of course you could always use the a tag in HTML.
EDIT: When you hover over a link, the browser displays the target. When you hover over a LinkButton, the browser displays the javascript call that will execute the function server side. I'd say the best you can do is display the target page in the ToolTip, since I think it would be pretty tough to display it in the browser.
If you use a LinkButton you will be able to set the command arguments and the onclick method in your code behind. By doing so, you will no longer be able to open the link in a new window as you have found out.
One of the reasons that you cannot open a LinkButton in a new window is because it is doing a postback to the same page.
I think you either have to use a HyperLink control and pass the command argument as a query string parameter or use a LinkButton control and loose the open in a new tab functionality.
If you pass the argument as a query string parameter, then you can check for that param in page load and still call your onclick function which you were going to use for your LinkButton.
Hope this is clear and it helps you.

Setting default button in asp.net 2.0

I have 3rd party user control (a captcha control), which has a captcha image, a text box within it.
I am using the above user control in my webpage. I have a 3 submit buttons on my webpage (Validate Captcha, Submit Page, Add User). When I click the Validate Captcha submit button using the mouse, I am validating whether captcha is empty and showing a javascript alert.
The problem comes when I enter the valid captcha text in the textbox and hit enter key when the cursor is in the textbox. The page just refreshes. I am unable to add keypress event to textbox and call Validate Captcha button event as I am using the 3rd party user control which I cannot modify.
Also, Page.ClientScript.RegisterHiddenField(...) will not work in my case as I have two other submit button inside the same page.
Only option left is to enclose these in panels and set default button.
Please let me know if anyone has any better options for achieving this.
Greetings! I too use alot of third party controls. The thing to remember about these controls, it that in the end they just emit HTML. This means you can use the DOM to access and attach event handlers such as onKeyPress. The trick is to identify how your control creator named the control you are looking for, in this case a {textbox}. The easiest way to achieve this is to simply run the page and view the page source. It is there that you can find the name as it is rendered and sent to the browser, after that all you have to do us use document.getElementByID to get the object and setup your handler
Example:
<script>
//Place this AFTER your textbox control is declared in the HTML
//Get the textbox
var textbox = document.getElementById('nameOfRenderedControlHere');
//Assign the event handler and function you want it to call
textbox.onclick = function() { validateCaptcha(); };
function validateCaptcha()
{ //Do your Stuff here }
</script>
That should be it..havent tested, let me knwo if you run into questions.
Put the captcha in its own <asp:Panel> and add a DefaultButton property for the panel with the ID of the captcha's submit button.

How to hide the cancel button on an ASP.NET ChangePassword control

I'm considering using the ChangePassword control on an ASP.NET 2.0 Webform. I don't want the 'cancel' button to show.
Is there a good way to hide it without resorting to silly "width = 0" sort of games?
Or perhaps there's a generic way to walk through the parts of a composite control like this
and hide individual parts?
Set CancelButtonStyle.CssClass to something like "hiddenItem" and set the CSS to "display:none".
Otherwise you can convert the control to a template and simply delete away the cancel-button manually. When you click the control in Design-mode in Visual Studio, you get a little arrow with options and one of them is "Convert to Template".
A quick an easy way just using your .aspx page is to set these cancel button properties on the changepassword control:
CancelButtonType="Link"
CancelButtonText=""
You can use the ChangePassword.CancelButtonStyle Property to set the CSS-class on the Cancel Button. Then just apply "display: none" on the specified class.

Resources