User Control Button Not Firing on Sharepoint Webpart - sharepoint-2010

I have a button that I am adding to a usercontrol(.ascx) that is being displayed in sharepoint as a webpart.
<asp:Button ID="btnCCA_UserAdministration_NewUser" runat="server" Text="Request User" OnClick="btnCCA_UserAdministration_NewUser_Click" >
However the button click action will not fire:
protected void btnCCA_UserAdministration_NewUser_Click(object sender, EventArgs e)
{
btnCCA_UserAdministration_NewUser.Visible = false;
}
I am not getting any error messages or anything. The onload events seem to be working fine. Any thoughts on what I am doing wrong?

we need more .ascx code, and try to change "to any CPU" in solutions

Related

Button color change on click or hover

I added a button component in my application, and I am expecting it to change the color when user hovers on it or click it.
But looks like that's not the default behavior of the button.
Is there a way to get that behavior maybe by setting some attribute?
You can simply use a event handler to set the color of the button when clicking it.
Here's the code sample below for your reference:
<Button Clicked="Button_Clicked">
Code in backend:
private void Button_Clicked(object sender, EventArgs e)
{
var button = (Button)sender;
button.BackgroundColor = Color.FromArgb("#FFA07A");
}
Update:
I found a simialr issue for your scenerio in Github, you can follow it up here:https://github.com/dotnet/maui/issues/9552

Hide virtual keyboard in windows 8 metro

Now i am working on Windows 8 Metro application. For that i have a popup window with textbox and OK button. I need to hide Virtual Keyboard when "Enter" is clicked on Virtual keyboard. If i click "OK" button on popup keyboard hides automatically.
I got this Link as good reference (using HiddenField). Is there any way to done this work without using "HiddenField". Thanks in advance..
Well finally found a solution for this issue.. I just change the focus from textbox to button in my popup.. below is the sample code..
public void FocusTextbox(object sender, EventArgs e)
{
// set focus to textbox on popup open
Textbox.Focus(Windows.UI.Xaml.FocusState.Programmatic);
}
public void Textbox_KeyDown(object sender, KeyRoutedEventArgs e)
{
// conforming the "Enter" button click
if (e.Key == Windows.System.VirtualKey.Enter)
{
// change the focus to OK button
this.OkButton.Focus(Windows.UI.Xaml.FocusState.Pointer);
}
}
Change the focus before closing the popup... it works great now..
And changing the focus to Label or Textblock is not hiding the Virtual keyboard...
i was also looking for this , but i found this approach first

Close popup modal dialog on clicking the submit button in sharepoint custom form

I have a custom form and I would like to add some functionality in my submit button. When I click on Submit button, I would like to close the popup and refresh the parent page.
I used this code in my button but there is a problem. It does not validate the controls and it makes a postback and even does not save any data.
OnClientClick="javascript:window.frameElement.commitPopup();"
Can you help me with some working code?
Thank you.
You need to set OnClientClick property after the code you want to be executed.
protected void btnAdd_Click(object sender, EventArgs e)
{
//Your Code here(some functionality)
Context.Response.Write(#"<script type='text/javascript'>window.frameElement.commitPopup(); return false</script>");
Context.Response.Flush();
Context.Response.End();
}

SharePoint 2010: Create "Alert Me" button

Hopefully this is an easy one...
I need to create an "Alert Me" button on my custom SharePoint masterpage which when clicked, will direct the user to a pre-populated "New Alert" page for that particular site/list. The OOTB blog site template already features this exact same button at the bottom of the default.aspx page, it's markup is as follows:
http://server/currentsite/_layouts/SubNew.aspx?List={00000000-0000-0000-0000-000000000000}&Source=http://server/currentsite/default.aspx
Does anyone know if there is an OOTB control or web part that I can just drop into my page layout to reproduce this?
Obviously I could create the button dynamically in the codebehind of my page layout if need be, but I'd be surprised if there isn't a pre-written control already.
Thanks in advance...
For those insterested, I ended up rolling my own usercontrol for this. Code is as follows:
HTML
<asp:HyperLink ID="AlertHyperLink" runat="server"><img alt="Alert me" src="/_layouts/images/menualert.gif" title="Alert me to any changes that get made to this site." /></asp:HyperLink>
C#
protected void Page_PreRender(object sender, EventArgs e)
{
// If the current page is not associated with a list, then hide the list-sensitive tools.
if (SPContext.Current.List != null)
{
this.AlertHyperLink.NavigateUrl = string.Format(
"{0}/_layouts/SubNew.aspx?List={{{1}}}&Source={2}",
SPContext.Current.Web.Url,
SPContext.Current.List.ID.ToString(),
this.Server.UrlEncode(this.Page.Request.Url.ToString()));
}
else
{
this.AlertHyperLink.Visible = false;
}
}

FindControl in DataList Edit Mode

As a new .net/C# web begginner, I always get tripped up when I try to use FindControl. Blam -flat on my face. Here is my current FindControl problem:
I have an .aspx page and Form, then ajax updatePanel, inside it there is my DataList (DataList1) that has an EditItemTemplate: that has the following:
<EditItemTemplate>
<asp:Label ID="thumbnailUploadLabel" runat="server" text="Upload a new thumbnail image:"/><br />
<asp:FileUpload ID="thumbnailImageUpload" runat="server" />
<asp:Button ID="thunbnailImageUploadButton" runat="server" Text="Upload Now" OnClick="thumbnailUpload"/><br />
</EditItemTemplate>
In my C# code behind I have the OnClick code for the fileUpload object:
protected void thumbnailUpload(object s, EventArgs e)
{
if (thumbnailImageUpload.HasFile)
{
//get name of the file & upload
string imageName = thumbnailImageUpload.FileName;
thumbnailImageUpload.SaveAs(MapPath("../../images/merch_sm/" + imageName));
//let'em know that it worked (or didn't)
thumbnailUploadLabel.Text = "Image " + imageName + "has been uploaded.";
}
else
{
thumbnailUploadLabel.Text = "Please choose a thumbnail image to upload.";
}
So of course I'm getting "Object reference not set to an instance of an object" for the FileUpload and the Label.
What is the correct syntax to find these controls, before dealing with them in the OnClick event?
The only way Ive used FindControl is something like:
label thumbnailUploadLabel = DataList1.FindControl("thumbnailUploadLabel") as Label;
But of course this is throwing the "Object reference not set to an instance of an object" error. Any help is very much appreciated.
(I've also seen the 'recursive' code out there that is supposed to make using FindControl easier. Ha! I'm so green at C# that I don't even know how to incorporate those into my project.)
Thanks to all for taking a look at this.
I know this is a hell lot late but i was looking for questions to answer....you must have figured it by now but still
if you add these lines in your code
protected void thumbnailUpload(object sender, EventArgs e)
{
FileUpload thumbnailImageUpload =(FileUpload)DataList1.Items[DataList1.EditItemIndex].FindControl("thumbnailImageUpload");
Label thumbnailUploadLabel = (Label)DataList1.Items[DataList1.EditItemIndex].FindControl("thumbnailUploadLabel");
if (thumbnailImageUpload.HasFile)
{
//Your code here
}
else
{
thumbnailUploadLabel.Text = "Please choose a thumbnail image to upload.";
}
}
this will find the appropriate control for the row you are editing...
also keep your Datalist out of the UPdate Panel beacuse Update Panels are not compatible with FileUpload. if you do the code will run but it will always show thumbnailImageUpload.HasFile as False.