I have a PeopleEditor in usercontrol (Visual webpart). I try to set the value of PeopleEditor field on page load through below code.
But it is empty, and it works fine other than if (!IsPostBack) part.
if (!IsPostBack)
{
PeopleEditor box1 = (PeopleEditor)GridViewMatrix.Rows[0].Cells[1].FindControl("PeopleEditorApprover");
box1.CommaSeparatedAccounts="domain\user";
}
<spuc:PeopleEditor ID="PeopleEditor1" runat="server" Width="100%" class="fieldName" CommaSeparatedAccounts='<%# Bind("Approver")%>'
AllowEmpty="true" MultiSelect="false" SelectionSet="User,SecGroup,SPGroup" Font-Size="Medium"/>
Any solution?
Related
I'm trying to go to another page when clicking a button. How could i do this.
I tried using a NavigationViewItem but it didn't work.
The NavigationViewItem you posted is used in UWP.
If it is a WinUI3 project, then you need to refer to this document, use Navigate.
the relevant code samples are as follows.
xaml
<Button x:Name="myButton" Click="myButton_Click"/>
xaml.cs
private void myButton_Click(object sender, RoutedEventArgs e)
{
Frame rootFrame = new Frame();
this.Content = rootFrame;
rootFrame.Navigate(typeof(BlankPage1), null);
}
i'm trying to create a login form using the textbox of bunifu but when i do set the properties: isPassword to true it seems not working. how can i solve this?
same with me, the isPassword method not working.
You can try make the textbox isPassword every value change on the textbox using this code
private void txtMyTextBox_OnValueChanged(object sender, EventArgs e)
{
txtMyTextBox.isPassword = true;
}
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
I'm using gridview with templates to show and edit some information from a sql database.
When I edit and change the data in that row and then click enter it automatically presses the highest on page button which uses submit to server set to true which means it'll try to delete instead of update.
I've have tried setting a panel round the gridview and setting the panel's default button to the "updatebutton" but it won't allow that because it can't 'see' the buttons.
I had a similar problem and I found a very simple workaround:
Place a button below the GridView and make it invisible by CSS (i.e. position: relative; left: -2000px)
Create a Panel around the GridView and give it as DefaultButton the ID of the button we just created.
Write the following line of code for the click-event of the button:
myGridView.UpdateRow(myGridView.EditIndex, false);
Whenever you press enter in the GridView now, the edited row will be confirmed.
You need to precess KeyDown or KeyPress event of the grid, and check if pressed key if Keys.Enter :
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void dataGridView1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
button1_Click(this, EventArgs.Empty);
}
}
private void button1_Click(object sender, EventArgs e)
{
// Your logic here
}
}
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.