|
im having some troubles in firing imagebutton click event in a user control which is loaded when the combo selectedIndexChanged event fires...
the user control is this
<div id="rowsBg" class="rowsBgSearchStaff" runat="server">
<div id="trashHolder" class="buttonHolder">
<asp:ImageButton ID="btnTrash" CssClass="btnTrashSearch" ToolTip="حذف"
ImageUrl="~/img/btnsearchtrash.png" runat="server" onclick="btnTrash_Click" />
</div>
<div id="separator1" class="separatorSearchStaff">
</div>
<div id="editHolder" class="buttonHolder">
<asp:ImageButton ID="btnEdit" CssClass="btnEditSearch" ToolTip="ویرایش"
ImageUrl="~/img/btnsearchedit.png" runat="server"
onclick="btnEdit_Click" />
</div>
<div id="separator2" class="separatorSearchStaff">
</div>
<div id="infoStaffHolder" class="staffinfoHolder">
<asp:Label ID="lblStaffInfo" runat="server">Name, Family, Code</asp:Label>
</div>
</div>
and these are events:
protected void btnTrash_Click(object sender, ImageClickEventArgs e)
{
dbm.Execute(String.Format("delete from Staff where Code='{0}'", StaffCode));
dbm.Execute(String.Format("delete from Contract where StaffCode='{0}'", StaffCode));
dbm.Execute(String.Format("delete from WardStaffs where StaffCode ='{0}'", StaffCode));
rowsBg.Visible = false;
}
protected void btnEdit_Click(object sender, ImageClickEventArgs e)
{
Response.Redirect(String.Format("EditStaff.aspx?sid={0}", StaffCode));
}
TIP: dbm is an instance of my databasemanager class
in my aspx page I use below codes to add control manually
protected void cmbBxWard_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
{
if (dbm.Read(String.Format("select * From Staff where Staff.Code in (select StaffCode from WardStaffs where WardCode={0})", cmbBxWard.Items[cmbBxWard.SelectedIndex].Value)))
{
foreach (DataRow dr in dbm.DT.Rows)
{
Control cnt = Page.LoadControl("StaffItem.ascx");
StaffItem staff = (StaffItem)cnt;
staff.StaffCode = dr["Code"].ToString();
itemHolder.Controls.Add(staff);
}
}
}
itemHolder is my div tag which hast runat="server" attribute
StaffItem is my control
after I change the selected item in my combobox I will click the btnEdit of my control
but it does not fire
why?
help me please
Do not Judge me...
I'm Persian!
|
|
|
|
|
i have to read the .xlsx file from SFTP server and save the con tents to the database.
i have used Renci.SshNet.dll to download the file from SFTP.
as sftpClient.DownloadFile(localfilePath, memorystream);
when i convert this memorystream into string[] as
byte[] byteArray = memorystream.ToArray();
var table = (Encoding.Default.GetString(byteArray , 0, byteArray.Length - 1)).Split(new string[] { "\r\n", "\r", "\n" }, StringSplitOptions.None);
this returns the string as encrypted text.
please help/suggest to convert this format.
|
|
|
|
|
It's not encrypted text; it's a zip file containing various parts of the Excel document.
If you're only ever dealing with .xlsx files (Excel 2007 or later), you could use the OpenXML SDK[^]. However, it will probably be easier to use a higher-level library such as EPPlus[^] or ClosedXML[^].
If you ever need to open older .xls files, then NPOI[^] is probably the simplest option.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
all is clear in the title. i have a code but i don't know why it's not working :
protected void btnUpdate_Click(object sender, EventArgs e)
{
#region @
try
{
string myid = string.Empty;
for (int i = 0; i < gv_enfant.Rows.Count; i++)
{
var chbox = gv_enfant.Rows[i].Cells[0].FindControl("CheckBoxenfant") as CheckBox;
var codeenfant = gv_enfant.Rows[i].Cells[0].FindControl("codeenfant") as HiddenField;
if (chbox != null && codeenfant != null)
{
if (chbox.Checked)
{
myid = codeenfant.Value;
}
}
}
Response.Write("myid = " + myid);
c.cmd = c.cn.CreateCommand();
c.cmd.CommandText = "update Enfants set prenom =@prenom, DateNaissance=@dateNaissance, Scolarise=@scolarise, Activite=@activite where codeEnfants=@codeEnfants";
if (c.cn.State == ConnectionState.Closed)
{
c.cn.Open();
}
c.cmd.Parameters.Add("@prenom", SqlDbType.VarChar);
c.cmd.Parameters.Add("@dateNaissance", SqlDbType.Date);
c.cmd.Parameters.Add("@scolarise", SqlDbType.VarChar);
c.cmd.Parameters.Add("@activite", SqlDbType.VarChar);
c.cmd.Parameters.Add("@codeEnfants", SqlDbType.Int);
c.cmd.Parameters["@prenom"].Value = TextBox_NPmodif.Text;
c.cmd.Parameters["@dateNaissance"].Value = TextBox_DNmodif.Text;
c.cmd.Parameters["@scolarise"].Value = TextBox_Scolarisemodif.Text;
c.cmd.Parameters["@activite"].Value = TextBox_Activitemodif.Text;
c.cmd.Parameters["@codeEnfants"].Value = myid;
c.cmd.ExecuteNonQuery();
gv_enfant.DataBind();
Response.Write("<script>alert('Opération reussie')</script>");
}
catch (SqlException sqlEx)
{
Response.Write("error" + sqlEx.Message);
Response.Write("<script>alert ('Erreur lors de la modif!')</script>");
}
finally
{
if (c.cn.State == ConnectionState.Open)
{
c.cn.Close();
}
}
#endregion
}
thank you
|
|
|
|
|
im just trying in the begenin to get the id "codeEnfants" which is hidden id the gridview in collumn 0
|
|
|
|
|
Member 10367981 wrote: i don't know why it's not working
"it's not working" is not specific enough for anyone to help you. Please describe the problem and any error messages you receive.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Hello,
You can use following code to get values.
string myid = string.Empty;
for (int i = 0; i < gv_enfant.Rows.Count; i++)
{
GridDataControlFieldCell cell = gv_enfant.RowsInViewState[i].Cells[0] as GridDataControlFieldCell;
CheckBox chbox = cell.FindControl("CheckBoxenfant") as CheckBox;
HiddenField codeenfant = cell.FindControl("codeenfant") as HiddenField;
if (chbox.Checked == true)
{
myid = codeenfant.Value;
}
}
|
|
|
|
|
How can I build a page with two listbox with sql datasource and both button in order to move items from left listbox to right listbox and double click event?
|
|
|
|
|
Have you done anything so far? Show some effort (coding) to us. As is it ain't a question...
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)
|
|
|
|
|
Hi,
you can try this.
<div class="sellistbox">
<asp:Label ID="lblAllUsers" runat="server" Text="All ids" CssClass="sideheading"
meta:resourcekey="lblAllUsersResource1"></asp:Label>
<asp:ListBox ID="lstUserNames" SelectionMode="Multiple"
runat="server" CssClass="listbox"
meta:resourcekey="lstUserNamesResource1"></asp:ListBox>
</div>
<div class="sellistbox_btns">
<asp:Button ID="btnMoveright" runat="server" Text=">"
CssClass="cd_submitbuttons" meta:resourcekey="btnMoverightResource1" style="margin: 0 0 8px 25px"></asp:Button>
<asp:Button ID="btnMoveleft" runat="server" Text="<"
CssClass="cd_submitbuttons" meta:resourcekey="btnMoveleftResource1" style="margin: 0 0 0 25px"></asp:Button>
</div>
<div class="sellistbox">
<asp:Label ID="lblGroupUsers" runat="server" Text="Whitelisted Senderids"
CssClass="sideheading" meta:resourcekey="lblGroupUsersResource1"></asp:Label>
<asp:ListBox ID="lstUserNames2" SelectionMode="Multiple"
runat="server"
CssClass="listbox" meta:resourcekey="lstUserNames2Resource1"></asp:ListBox>
</div>
********************************************************************************
Protected Sub btnMoveright_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnMoveright.Click
Dim oCsSender_IDs As String = ""
Dim oresult As Integer
For Each lstitem1 As ListItem In lstUserNames.Items
If lstitem1.Selected = True Then
oCsSender_IDs &= lstitem1.Text & ","
End If
Next
If oCsSender_IDs = "" Then
LblResult.ForeColor = Drawing.Color.Red
LblResult.Text = " No SenderIds selected"
Exit Sub
End If
Dim omethodparams As String = ""
omethodparams = oCsSender_IDs.TrimEnd(",")
Dim ousername As String = ddlgwusers.SelectedItem.Text
oresult = objWhiteListSIDs_DAL.SaveWhiteListSIDs(ddlgwusers.SelectedItem.Value, oCsSender_IDs.TrimEnd(","), DateTime.Now.ToString())
If oresult < 0 Then
LblResult.Text = HidLblResultFail.Value
Else
LblResult.Text = HidLblResultSuc.Value
End If
LoadSenders(ddlgwusers.SelectedItem.Value, 2)
BindWhiteListSids(ddlgwusers.SelectedItem.Value)
End Sub
Protected Sub btnMoveleft_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnMoveleft.Click
Dim oCsSender_IDs As String = ""
Dim oresult As Integer
For Each lstitem1 As ListItem In lstUserNames2.Items
If lstitem1.Selected = True Then
oCsSender_IDs &= lstitem1.Text & ","
End If
Next
If oCsSender_IDs = "" Then
LblResult.ForeColor = Drawing.Color.Red
LblResult.Text = " No SenderIds selected"
Exit Sub
End If
Dim omethodparams As String = ""
omethodparams = oCsSender_IDs.TrimEnd(",")
Dim ousername As String = ddlgwusers.SelectedItem.Text
oresult = objWhiteListSIDs_DAL.DeleteWhiteListSIDs(ddlgwusers.SelectedItem.Value, oCsSender_IDs.TrimEnd(","))
If oresult < 0 Then
LblResult.ForeColor = Drawing.Color.Red
LblResult.Text = HidDelFail.Value
Else
LblResult.ForeColor = Drawing.Color.Red
LblResult.Text = HidDelsuc.Value
End If
End Sub
|
|
|
|
|
Dear all,
I am trying to construct a method, which can allow specific users to be redirected to their specific api controllers. I have come up with a psuedo-code however, I am little stuck implementing this method as i keep getting errors. Any help/advice would be very helpful.
public class MultiController : ApiController
{
if (User.IsInRole("admin"))
{
[ActionName(BwicController)]
}
else (User.IsInRole("user"))
{
[ActionName(IntexController)]
}
}
This is the class where the user credentials are stored:
public class PrincipalPro : IProvidePrincipal
{
private const string Username = "###";
private const string Password = "###";
public IPrincipal CreatePrincipal(string username, string password)
{
if (username != Username || password != Password)
{
return null;
}
var identity = new GenericIdentity(Username);
IPrincipal principal = new GenericPrincipal(identity, new[] { "admin" });
return principal;
}
}
|
|
|
|
|
I'm not sure if I understood your question correctly. If you just want single action method that behaves differently depending on user's group then just implement the logic there.
If the redirect part is important then in default action method redirect the response to correct action. However that won't stop users from typing "wrong" URL (i.e. user typing admin's url), so you would have to check access anyway.
--
"My software never has bugs. It just develops random features."
|
|
|
|
|
Thank you very much for your response.
deflinek wrote: If you just want single action method that behaves differently depending on user's group then just implement the logic there.
I would like to clarify your above statement, if you are suggesting I implement the logic in the "MultiController" class or "PrincipalPro" class.
Currently I have two users group full and limited. I have to provide data api controller (localhost/api/data) to user group 'full' and data2 api controller to user group 'limited'. I would like to be able provide one link to the users, where they login and the system automatically redirects them correct data controllers.
So my question is, that is their specific filter/method function i could use or some kind of example/framework i can use a guide for this logic, as I am currently struggling to out this together.
I hope this clarifies my issue a little clearer.
Thank you for your help.
|
|
|
|
|
I suggest to implement the logic in MultiController class. I assume you need to return different set of data depending on their role. In that case you can attribute the MultiController class with [Authorize] so you force user to login before accessing it's methods, then return different data depending on user's role.
i.e.
public SomeResult Get()
{
if(User.IsInRole("Admin"))
{
return FullData();
}
else
{
return RestrictedData();
}
}
Does it make sense?
--
"My software never has bugs. It just develops random features."
|
|
|
|
|
I am writing to seek help, as I am experiencing - No overload for method 'Get' takes 0 arguments error, on the "return result.Get();" line of user controller class.
public class UserController : ApiController
{
public HttpResponseMessage Get([FromUri] Query query)
{
if (User.IsInRole("admin"))
{
var result = new ValuesController();
return result.Get();
}
}
}
public class ValuesController : ApiController
{
private cdwEntities db = new cdwEntities();
public HttpResponseMessage Get([FromUri] Query query)
{
var data = db.database.AsQueryable();
if (query.name != null)
{
data = data.Where(c => c.Name == query.name);
}
if (query.price != null)
{
data = data.Where(c => c.Price == query.price);
}
if (!data.Any())
{
var message = string.Format("error");
return Request.CreateErrorResponse(HttpStatusCode.NotFound, message);
}
return Request.CreateResponse(HttpStatusCode.OK, data);
}
}
Any advice would be very much appreciated. Many thanks.
|
|
|
|
|
Please try
return result.Get(query);
on 8th line
--
"My software never has bugs. It just develops random features."
|
|
|
|
|
Hi,
Kindly suggest me that, i want to schedule any operation (eg. mailing daily report)on the server side in ASP.Net MVC. I searched over internet and found that either use Windows Service or console app. I need suggestion regarding whether i use Window service or console app (or any other solution), kindly suggest me what if i have hosting with shared server.
Thanks
|
|
|
|
|
The best solution depends on your hosting options. Windows service is good solution and widely used (at least in companies I worked for ) however requires admin access to the server that is usually much more expensive.
If your hosting allows for scheduled "execute url" task, then you can create an action to send your report and schedule it for daily execution.
--
"My software never has bugs. It just develops random features."
|
|
|
|
|
"If your hosting allows for scheduled "execute url" task, then you can create an action to send your report and schedule it for daily execution."
Kindly can you please elaborate little more the above statement.
Are you talking about task scheduler?
And Thanks for your reply deflinek
|
|
|
|
|
The asp.net hosting that I use for my personal website allows for scheduled tasks apart of the website itself. There are some preset types of tasks I can choose from - database backup, send email, send files by ftp and check if website is alive.
The last one allows me to provide url that should be checked and I get an alarm email if response was anything but 200.
I use that for weekly reports as the url I provided generates the reports and sends emails.
As the hosting I use is quite cheap (about $35 per year), I think other hosting companies provide similar functionality.
--
"My software never has bugs. It just develops random features."
|
|
|
|
|
Thanks deflinek i got your point.
|
|
|
|
|
Assume that there is a web application has been hosted in IIS. And there are three users trying to accesss that web application from three different machines. Now how does IIS handle all the http requests from three different machines to access the same web application?
Thanks & Regards
Ashok
|
|
|
|
|
The question is very broad and does not point to any specific problem or issue.
Ashok Natarajan wrote: Now how does IIS handle What do you mean by how?
|
|
|
|
|
|
How to apply CSS to Ajax HtmlEditor Control.
I have created a Layout that i want to bind with the HtmlEditor Hoe can i do that? need Help ????
|
|
|
|