Subscribe: Web Forms
http://forums.asp.net/rss.aspx?ForumID=18
Added By: Feedage Forager Feedage Grade B rated
Language: English
Tags:
cmd parameters  cmd  eval  new  parameters addwithvalue  parameters  runat server  runat  server  string  system  tostring  user 
Rate this Feed
Rate this feedRate this feedRate this feedRate this feedRate this feed
Rate this feed 1 starRate this feed 2 starRate this feed 3 starRate this feed 4 starRate this feed 5 star

Comments (0)

Feed Details and Statistics Feed Statistics
Preview: Web Forms

All Forums



All Forums



Last Build Date: Wed, 17 Jan 2018 12:33:10 -0800

 



Sql query not work in Listview SelectedIndexChanging

2018-01-17T19:23:14.627-08:00

(image)














(image) ' />









 protected void IMGLV_SelectedIndexChanging(object sender, ListViewSelectEventArgs e)
        {
            ListViewItem item = (ListViewItem)IMGLV.Items[e.NewSelectedIndex];


            Label lb = (Label)item.FindControl("pImageidtxt");
            uPid = lb.Text.ToString();

            cmd = new MySqlCommand("SELECT * FROM pImg WHERE ID=@uPid", cn);
            cmd.Parameters.AddWithValue("@uPid", uPid.ToString());
            cn.Open();
            dr = cmd.ExecuteReader();
            
            if(dr.Read())
            {
                sURL = dr["URL"].ToString();
            }
           
            
            cn.Close();

            cmd = new MySqlCommand("UPDATE users SET userPhoto = @sURL WHERE ID=@userid", cn);
            cmd.Parameters.AddWithValue("@sURL", sURL.ToString());
            cmd.Parameters.AddWithValue("@userid", userid);
            cn.Open();
            cmd.ExecuteNonQuery();
            cn.Close();
        }

Sql queries work fine in another event, but in the selectedindexchanging event the "sURL" string value is null. Normally, tabloda image URLs are included.

With the link button I click, I can get the index ID without any problems. I just can not get the URL.




SMTP not sending

2018-01-16T23:41:17.01-08:00

Hello

Is there an obvious reason, please, why the following SMTP code is not working? When the form fields are completed and the 'Send' button pressed, the typed in fields don't even disappear.

The page is here: http://www.dimadayoub.net/frina/Contact.aspx

The IP address, server port, and passwords are all correct.

Imports System
Imports System.Linq
Imports System.Web
Imports System.Web.UI
Imports System.Net
Imports System.Net.Mail
Imports System.IO

Public Class Contact
    Inherits System.Web.UI.Page

Private Sub SendEmail_Click(sender As Object, e As System.EventArgs) Handles SendEmail.Click

Dim myMessage As New MailMessage
Dim Smtpserver As New SmtpClient

Dim user_name As String = Request.Form("your_name") 'user_name is the TextBox ID
Dim user_email As String = Request.Form("your_email") 'user_email is the TextBox ID
Dim user_subject As String = Request.Form("your_subject") 'user_subject is the TextBox ID
Dim user_message As String = Request.Form("your_message") 'user_message is the TextBox ID

'Request.Form - extract data from form fields and create the mail message

myMessage.From = New MailAddress(user_email) 'User's email
myMessage.To.Add(New MailAddress("myEmail1@Mail.Com")) 'Webmaster
myMessage.CC.Add(New MailAddress("myEmail2@Mail.com")) 'Webmaster's assistant
myMessage.Subject = user_subject
myMessage.Body = user_message

myMessage.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure
myMessage.IsBodyHtml = True
myMessage.Priority = MailPriority.High

Smtpserver.DeliveryMethod = SmtpDeliveryMethod.Network
Smtpserver.Host = ("IP_add")
Smtpserver.Port = 25
Smtpserver.EnableSsl = False

Dim basicAuthenticationInfo As New 
System.Net.NetworkCredential("info@myPage.net", "Pwd")
Smtpserver.Credentials = basicAuthenticationInfo
'Smtpserver.UseDefaultCredentials = False
Smtpserver.Send(myMessage)

myMessage.Dispose()
myMessage = Nothing
Smtpserver = Nothing

pnlFormFields.Visible = False
pnlThankYouMessage.Visible = True

End Sub

End Class

Thanks




One View, One Form, two controllers

2018-01-17T16:06:47.54-08:00

Hello,

I need some help with this, and I should tell I'm new at this.  It goes this way:

Im using ASP.Net MVC, AdoModel

  • Two Tables: Projects and Engineer
  • One controller for creating a new record of a new project. 

When I want to create a new record(project) I also want to add to it a Engineer (it can be zero, one or many). So, while creating the new record(project), I want to create new records of engineers to the engineering table.

Can somebody help me on this? Please.

Not good at english.

Summary of the problem I am having:

I need to create two records in one form, for two different table.

Error I am receiving:

NOT ERROR

My code:

NO CODE




datata binding

2018-01-17T19:51:22.87-08:00

hello all this is my first post here ...  i have problem with my slideshow i put data list for image and repeater for the video ..... my problem is when i have empty video it show in slide just the img without the video because its empty .pls if u could help me i want to hide the repeater which control the video if empty im using asp.net vb 2010 in it inside grid view my code is  :



Please fix this

2018-01-17T18:32:29.457-08:00

Here's the original text of my post, typed out in Notepad:

(image)

Here's what it looked like when I post it to ASP.NET forums:

(image) in post" width="1264" height="908">

Not my fault. Please fix this.

Here's the post: https://forums.asp.net/p/2134972/6187580.aspx?p=True&t=636517813529048400




How could I access a DropDownList inside a DataList by its UniqueID?

2018-01-17T06:06:12.357-08:00

I do have a DropDownList control inside a DataList. When the sqlDataSource that feed the DataList find several records, as many DropDownList Controls are display in the DataList. Let’s say that I click one of the DropDownList and change its value. Since I do not want another DropDownList with the same value on the page how can I change the other DropDownList to a different value if I know its particular UniqueID. This is the way that I’m finding the DropDowList UniqueID in code behind:

'Here we get the clicked ddl unique ID
        ClickedDDLForVoteUniqueID = CType(itemDDL.FindControl("SelectionForVotingDropDownList"), DropDownList).UniqueID.ToString
        Label3.Text = "This is the clicked DDL control Unique ID: " + ClickedDDLForVoteUniqueID

If there is any other way to do things, I will appreciate your suggestions as well. Your code must be in Visual Basic
 Thanks to all.




response sending back NullReferenceException

2018-01-17T18:47:48.283-08:00

Hello,
 
I'm having an issue returning data from a web API call.
 
The web API function looks like this:
 
        public async Task GetProjects()
        {
            var projects = _projectService.GetProjects().ToList();
            return Request.CreateResponse(HttpStatusCode.OK, projects, System.Net.Http.Formatting.JsonMediaTypeFormatter.DefaultMediaType);
        }
 
The problem is that the results that return say there was a NullReferenceException. I know that the list of projects that's returned is not null or empty. I think it has something to do with the json formatter.
 
Any suggestions?



Type 'Warning' is not declared

2018-01-08T21:54:39.693-08:00

We copied a website and SQL database from a 2008R2 Server to a 2016 Server and are getting the error above on a code page on the new server.  This happened once before and old notes indicate was fixed by adding a reference to Microsoft.ReportViewer.WebForms dll but that was done when it was on the 2008R2 Server and all files and folders of the website were copied to the new 2016 server and web application in IIS.  How can I resolve this issue? Below is code from the module where it is failing.  The error points to the line that says  Dim warnings As Warning() = Nothing Imports System Imports System.IO Imports Microsoft.Reporting.WebForms.Internal.Soap.ReportingServices2005.Execution Imports System.Data.OleDb Imports Microsoft.VisualBasic Imports System.Data Imports System.Drawing Imports System.Drawing.Imaging Public Shared Function CreatePDFReport(ByVal strReportName As String, _ ByVal intRecordID As Int32, _ Optional ByVal intType As Int16 = 1) As String Dim strReturn As String = "" ' Output variables Dim encoding As String Dim mimeType As String Dim extension As String Dim warnings As Warning() = Nothing Dim streamIDs As String() = Nothing ' ReportExecution object prepare Dim rs As New ReportExecutionService() rs.Credentials = System.Net.CredentialCache.DefaultCredentials rs.Url = UtilClass.GetReportServerPath & "/ReportExecution2005.asmx" ' Render arguments Dim result As Byte() = Nothing Dim strFileName As String = "" Dim reportPath As String = "/BodyShopReports/" Dim format As String = "PDF" Dim historyID As String = Nothing Dim devInfo As String = "False" Dim strOutputPath As String = HttpContext.Current.Server.MapPath("~/OfficeDocs/POFiles") ' Prepare report parameters Dim parameters As ParameterValue() Select Case strReportName Case "WorkAuthorization" parameters = New ParameterValue(1) {} parameters(0) = New ParameterValue() parameters(0).Name = "RecordID" parameters(0).Value = intRecordID parameters(1) = New ParameterValue() parameters(1).Name = "ReportType" parameters(1).Value = intType strFileName &= "\WorkAuth" & intRecordID.ToString Case "CustomerBilling" parameters = New ParameterValue(1) {} parameters(0) = New ParameterValue() parameters(0).Name = "RecordID" parameters(0).Value = intRecordID parameters(1) = New ParameterValue() parameters(1).Name = "ReportType" parameters(1).Value = intType strFileName &= "\FinalBill" & intRecordID.ToString Case "TasksAtDropOff" parameters = New ParameterValue(1) {} parameters(0) = New ParameterValue() parameters(0).Name = "RecordID" parameters(0).Value = intRecordID strFileName &= "\TasksAtDropOff" & intRecordID.ToString Case Else End Select Dim strFullPath As String = strOutputPath & strFileName & ".pdf" If File.Exists(strFullPath) Then '1-7-2015 added below to avoid exception error when same file name used Dim strTime As String = [...]



ASP.net Button click event firing twice sometimes

2018-01-17T18:29:20.43-08:00

Hello Friends , I have Button a inside gridview some times  Button click event firing twice not every time . Suppose 700 records inserted in data then 50 are repeated. i have checked everything but found nothing  .I don't know why its firing twice or more then that in single click sometime . i have also disabled thru client click but still going same thing . Here is my code: protected void btn_transfer_Click(object sender, EventArgs e){ string user_id="1"; GridViewRow gr = (GridViewRow)((Button)sender).Parent.Parent; TextBox txt_amt = (TextBox)gr.FindControl("txt_Amt_main"); decimal amount_entered = 0; if (decimal.TryParse(txt_amt.Text, out amount_entered)) { amount_entered = Convert.ToDecimal(txt_amt.Text); } amount_entered = amount_entered / 2; decimal cur_val = 15; string id = grd_withdrawal.DataKeys[gr.RowIndex].Values["Id"].ToString(); string incom_per = grd_withdrawal.DataKeys[gr.RowIndex].Values["incom_per"].ToString(); DataTable dt_user_wid_check = d.FillDataTable("SELECT typ FROM bl_r WHERE user_id='" + user_id + "'"); if (dt_user_wid_check.Rows.Count > 0) { d.executenonquery("update User_inc set inc_dis='Paid' where User_inc .id='" + id + "'"); d.messagebox("return msg..", this); fill_grd(); return; } string gid = Guid.NewGuid().ToString(); string query = @" begin tran T1 BEGIN TRY update User_inc set inc_dis='Paid' where User_inc .id='" + id + @"' insert into[tab_wt] (ins_date, user_id, coin_rate, coin_val_dr, coin_val_cr, purchase_from, staus, type, referance)values( dateadd(hh,2, cast(SWITCHOFFSET(TODATETIMEOFFSET(getdate(),'-05:00'),'+05:30') as datetime)), @user_id, @coin_rate, @coin_val_dr, @coin_val_cr, @purchase_from, @staus, @type,@referance) COMMIT TRAN T1; END TRY BEGIN CATCH ROLLBACK TRAN T1 END CATCH "; SqlCommand cmd = new SqlCommand(query, cn); cmd.Parameters.AddWithValue("@user_id",user_id); cmd.Parameters.AddWithValue("@coin_rate", cur_val); cmd.Parameters.AddWithValue("@amt_dr", amount_entered); cmd.Parameters.AddWithValue("@coin_val_dr", "0"); cmd.Parameters.AddWithValue("@coin_val_cr", (amount_entered * cur_val).ToString()); cmd.Parameters.AddWithValue("@purchase_from", "tnvu"); cmd.Parameters.AddWithValue("@staus", "Valid"); cmd.Parameters.AddWithValue("@type", "Purchase"); cmd.Parameters.AddWithValue("@referance", gid); cn.Open(); cmd.CommandTimeout = 1000; int icheck = cmd.ExecuteNonQuery(); cn.Close(); } <%# Container.DataItemIndex+1 %&g[...]



Can we hardcode the date for action link

2018-01-17T18:02:45.91-08:00

tell me can we hard code date as route data for action link?



Getting JsonSerializationException

2018-01-17T18:21:22.28-08:00

Hello,   I'm having an issue trying to convert an object to json. The error is a Newtonsoft.Json.JsonSerializationException:   Self referencing loop detected for property 'Project' with type 'System.Data.Entity.DynamicProxies.Project_F29F70EF89942F6344C5B0A3A7910EF55268857CD0ECC4A484776B2F4394EF79'. Path '[0].Categories[0]'.   The problem is that the object (it's actually a list of objects) has a property which is another object that refers back to the first object:    public partial class Project { ...     public virtual ICollection Categories { get; set; } ... }   public partial class Category { ...     public virtual Project Project { get; set; } ... }   This is all fine and dandy as far as Entity Framework is concerned, but to convert this to json would result in an infinite regress, hence the exception.   Here is my code:           public async Task GetProjects()         {             var projects = _projectService.GetProjects().ToList();             string jsonString = JsonConvert.SerializeObject(projects); // <-- Offending line             return Request.CreateResponse(HttpStatusCode.OK, jsonString);         }   I've looked online for solutions to this and I found this stackoverflow post:   https://stackoverflow.com/questions/7397207/json-net-error-self-referencing-loop-detected-for-type   They suggest three solutions, none of which work:   1) Ignore the circular reference:           public async Task GetProjects()         {             var projects = _projectService.GetProjects().ToList();             JsonSerializerSettings settings = new JsonSerializerSettings()             {                 ReferenceLoopHandling = ReferenceLoopHandling.Ignore             };             string jsonString = JsonConvert.SerializeObject(projects, settings);             return Request.CreateResponse(HttpStatusCode.OK, jsonString);         }   This resulted in the call to SerializeObject(...) hanging for a bit then throwing a  System.OutOfMemoryException (which tells me the circular references were NOT being ignored).   Mind you, the author of this proposed solution at stackoverflow says to set the ignore setting in WebApiConfig.cs but I tried that and it has no effect.   He also says:   "If you want to use this fix in a non-api ASP.NET project, you can add the above line to Global.asax.cs, but first add: var config = GlobalConfiguration.Configuration;"   Mine's a web API with no global file so I shouldn't have to do this.   I also don't want to ignore circular references because I don't want to lose data.   2) Preserve the circular reference:           public async Task GetProjects()         {             var projects = _projectService.GetProjects().ToList();             JsonSerializerSettings settings = new JsonSerializerSettings()             {                 ReferenceLoopHandling = ReferenceLoopHandling.Serialize,                 PreserveReferencesHandling =[...]



This message appears to me :Line 83: SqlDataReader rd = cmd.ExecuteReader();

2018-01-17T09:15:22.983-08:00

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data.SqlClient; using System.Data; using System.Configuration; public partial class student_usercontrol_examination : System.Web.UI.UserControl {     SqlConnection con;     SqlCommand cmd;     int correct_ans = 0;     int wrong_ans = 0;     int select_no = 0;     int count = 0;     public student_usercontrol_examination()     {         con = new SqlConnection();         con.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();         cmd = new SqlCommand();     }     protected void Page_Load(object sender, EventArgs e)     {         if (!Page.IsPostBack)         {             loadgrid();         }     }     private void loadgrid()     {         con.Open();         cmd.CommandText = "select*from[Question]";         cmd.Connection = con;         SqlDataReader rd = cmd.ExecuteReader();         GridView1.DataSource = rd;         GridView1.DataBind();     }     protected void Button1_Click(object sender, EventArgs e)     {         foreach (GridViewRow row in GridView1.Rows)         {             Label l1 = row.FindControl("QuestionId") as Label;             RadioButton r1 = row.FindControl("ans1") as RadioButton;             RadioButton r2 = row.FindControl("ans2") as RadioButton;             RadioButton r3 = row.FindControl("ans3") as RadioButton;             RadioButton r4 = row.FindControl("ans4") as RadioButton;             if (r1.Checked)             {                 select_no = 1;             }             else if (r2.Checked)             {                 select_no = 2;             }             else if (r3.Checked)             {                 select_no = 3;             }             else if (r4.Checked)             {                 select_no = 4;             }             con.Close();             check_number(l1.Text);         }         Response.Write("correct ans is" + correct_ans.ToString());     }      private void check_number(string text)      {          con.Open();          cmd.CommandText = "select*form[Question] where Question_Id=@qid"+count;          cmd.Parameters.AddWithValue("@qid"+count,text);          cmd.Connect[...]



How to call server side function from @Html.ActionLink

2018-01-17T14:42:43.633-08:00

please tell me can we call server side function from @Html.ActionLink ?

@Html.ActionLink("Delete Item", "", new { id = @feedback.Id, q=CallServerSideMethod() }, new { onClick = "confirmDelete("+feedback.Id+");return false;" })

see this area q=CallServerSideMethod() 

looking for suggestion. thanks




Always we need to use partialview when we use @Ajax.ActionLink

2018-01-17T14:46:47.69-08:00

@Ajax.ActionLink("Back", "PartialForm",
                      new AjaxOptions
                          {
                              UpdateTargetId = "formsIndex", // <-- DOM element ID to update
                              InsertionMode = InsertionMode.Replace, // <-- Replace the content of DOM element
                              HttpMethod = "GET" // <-- HTTP method
                          })

i saw when i worked with @Ajax.ActionLink and when i mention action name and when action return view then some html getting copied when new html render. so i search google and found people are saying return partial view from action instead of view. so tell me is it mandatory to use partial view from ajax action link ?




web form 2010 want intellisense when using jquery

2017-12-29T21:01:20.623-08:00

I am working with a vb.net 2010 web form application that uses jquery. In the original version of the code there were vsdoc files associated with the application so that intellisense worked in Visual Studio.

Now I am in the process of changing the application to use the current version of jquery. When I go to the jquery.com website to download the latest version of the jquery core library, there is not an option to download a vsdoc.

Thus can you tell me what I can do in visual studio 2010 to have intellisense work when I am accessing the current version of jquery?




web form gridview control concatenate values together in 1 field.

2018-01-17T04:24:47.083-08:00

In a vb.net 2010 web form application, I have a gridview control that is listed below in the code. In the following line of code: ', '<%# Eval("schoolnum") %>', '<%# Eval("milestone_code") %>', '<%# Eval("stulink") %>', '<%# Eval("HOMELNGCOR") %>', '<%# Eval("semester") %>');" style="color:Blue"><%#Eval("STUDENTNAME")%> , I would like to merge (concantenate) the field values of <%# Eval("HOMELNGCOR") %> with the value of grade that is listed in the gridview control that is listed in the gridview control. I would like the results of the field to be passed in the field called HOMELNGCOR with the value of Grade passed along together in this field. I would like to merge the to fields together since I would not need to rewrite the application. Would you tell me how to accomplish this goal? <%@ Page Title="" Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="default.aspx.vb" Inherits="letters_default" %>
', '<%# Eval("schoolnum") %>', '<%# Eval("milestone_code") %>', '<%# Eval("stulink") %>', '<%# Eval("HOMELNGCOR") %>', '<%# Eval("semester") %>');" style="color:Blue"><%#Eval("STUDENTNAME")%>


How to delete a page if sub report is blank?

2018-01-17T17:29:38.427-08:00

Hello,

I have an ASP.NET application written in C# with the Crystal report. Each page of this report has a header, which always has data, and also a sub report Notes that can be blank. I don't want to show pages that have blank sub report, I need to remove them completely. Without a header this would be pretty simple, but I cannot figure out how to do this in my case.

I'd appreciate your help. Thank you.




check only password

2018-01-17T16:24:39.727-08:00

I'm building a backend for an API. I just want to check the password for violations of duty like length or digits with api call. I don't want to change the password. second challenge is that I can't allow asyncrony in the function, because I use fluentvalidation.




Invoking command prompt from MVC using RunAs as different user

2018-01-09T05:17:44.467-08:00

I have a MVC application and inside the ActionResult I'm trying to invoke a command prompt but I want to invoke the command prompt using RunAs but it is throwing error.

public static void CommandPromptRunAs(string _commandParameter, string username, string password) { string _output = string.Empty; try { log.Info("Inside CommandPromptRunAs -"); Process cmd = new Process(); cmd.StartInfo.FileName = "cmd.exe"; cmd.StartInfo.RedirectStandardInput = true; cmd.StartInfo.RedirectStandardOutput = true; //cmd.StartInfo.CreateNoWindow = true; cmd.StartInfo.UseShellExecute = false; cmd.StartInfo.Domain = "dir"; cmd.StartInfo.UserName = username; cmd.StartInfo.Password = GetSecureString(password); cmd.StartInfo.WorkingDirectory = @"C:\Windows\System32"; 
cmd.StartInfo.Arguments = @"/c whoami";
cmd.Start(); cmd.StandardInput.WriteLine(_commandParameter.ToString().Trim()); cmd.StandardInput.Flush(); cmd.StandardInput.Close(); //Console.WriteLine(cmd.StandardOutput.ReadToEnd()); cmd.WaitForExit(); var originalConsoleOut = Console.Out; using (var writer = new StringWriter()) { Console.SetOut(writer); Console.WriteLine(cmd.StandardOutput.ReadToEnd()); writer.Flush(); // everything is written out _output = writer.GetStringBuilder().ToString(); log.Info("_output- " + _output.ToString()); } Console.SetOut(originalConsoleOut); ReturnOutput(_output); cmd.Close(); cmd.Dispose(); } catch (Win32Exception w32E) { // The process didn't start. log.Info("error as Win32Exception - " + w32E.StackTrace.ToString()); log.Info("error as Win32Exception - " + w32E.Message.ToString()); //Console.WriteLine(w32E); } catch (Exception ex) { // The process didn't start. log.Info("error as Exception StackTrace -" + ex.StackTrace.ToString()); log.Info("error as Exception Message -" + ex.Message.ToString()); //Console.WriteLine(ex); } } public static SecureString GetSecureString(string str) { SecureString result = new SecureString(); try { if (string.IsNullOrWhiteSpace(str)) return null; else { foreach (char c in str.ToCharArray()) result.AppendChar(c); return result; } } catch (Exception ex) { log.Info("Cannot create password-" + ex.StackTrace.ToString()); } return result; }

But when I'm trying to invoke I'm getting error in the windows event viewer.

Faulting application name: cmd.exe, version: 10.0.14393.0, time stamp: 0x57899a99
Faulting module name: KERNEL32.DLL_unloaded, version: 10.0.14393.1198, time stamp: 0x59028368
Exception code: 0xc0000005
Fault offset: 0x0000000000019bf0
Faulting process id: 0x542c
Faulting application start time: 0x01d3888ec96b977a
Faulting application path: C:\windows\SYSTEM32\cmd.exe
Faulting module path: KERNEL32.DLL
Report Id: d898012b-7838-4f14-9861-24e81c815049
Faulting package full name:
Faulting package-relative application ID: