Making an entire row in GridView a link? - c#

I'm trying to make a entire GridView row a link and I think I got it but I'm running into an issue. As you can see from below, all my query strings data is coming from the DB now i want to add a query string that is not coming from the DB, how could I accomplish this??
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string Types = Request.QueryString["Type"].ToString();
string Rounds = Request.QueryString["Rounds"].ToString();
string Groups = Request.QueryString["Groups"].ToString();
string Id = DataBinder.Eval(e.Row.DataItem, "Id").ToString();
string League = DataBinder.Eval(e.Row.DataItem, "League").ToString();
string Team1 = DataBinder.Eval(e.Row.DataItem, "Team1").ToString();
string Team2 = DataBinder.Eval(e.Row.DataItem, "Team2").ToString();
string Type = DataBinder.Eval(e.Row.DataItem, "TType").ToString();
string Location = ResolveUrl("Update_Match.aspx" + "?Id=" + Id + "&Team1=" + Team1 + "&Team2=" + Team2 + "&League=" + League + "&Type=" + Type + "&Types=" + Types + "&Rounds=" + Rounds + "&Groups=" + Groups);
e.Row.Attributes["onClick"] = string.Format("javascript:window.location='{0}';", Location);
e.Row.Style["cursor"] = "pointer";
}
}

I rewrote this a bit to try to understand your questions better. It's more verbose than you might want, but it will make it clearer. All you need to do is build a querystring from a number of elements, some of which come from your database, some from your prior page, and others may be hardcoded. That's all simple. Just assign each variable in the querystring its value first, then build the string.
For example, suppose you are grabbing the team name from the database using the ID like this:
String Team1 = db.Teams.Where(w => w.TeamID = TeamID).First().TeamName;
and you are setting the Type as a hardcoded value:
Int type = 0;
When you are done building your variables, just put them together like this:
string QS = "Id=" + ID.ToString();
QS = QS + "&Team1=" + Team1;
QS = QS + "&Team2=" + Team2;
QS = QS + "&League=" + League;
QS = QS + "&Type=" + Type.ToString();
QS = QS + "&Types=" + Types;
QS = QS + "&Rounds=" + Rounds.ToString();
QS = QS + "&Groups=" & Groups.ToString();
e.Row.Cells[0].Visible = false;e.Row.Attributes.Add("onclick", "location='newpage.aspx?" + sQueryString;
e.Row.Attributes.Add("style", "cursor:pointer;");
It doesn't matter how you acquire each value as long as they are converted into strings to build the querystring. Is there something more I'm missing?

It looks like your code should work. Do you get any script errors when you try to load the page?
Also, what browser are you testing this with?
I would try making the "c" in onClick lowercase to start with.
In addition to that, I would consider revising your code a bit because it appears as though you would be vulnerable to a cross site scripting attack because you are not cleaning the QueryString before putting it in the attribute.
An attacker could exploit this by modifying the queryString of the page to say:
http://www.yourpage.com/index.aspx?otherQueryString=3&Groups=<script>window.alert("Hello XSS!!");</script>

Related

Can Anyone help me retrieve data from parse using unity please?

I have managed to store data, but I can't retrieve it and i would be so grateful if someone could just help me get at least 1 example working.
First I am storing data when the user signs up:
public void SetupNewParseMember(ParseUser user)
{
ParseObject gameScore = new ParseObject("GameScore");
gameScore["cash"] = 500;
gameScore["playerName"] = user.Username;
gameScore["HighestCash"] = 500;
gameScore["GamesPlayed"] = 0;
Task saveTask = gameScore.SaveAsync();
}
This works fine, I can see the data in parse and all seems ok..
The problem is when i try to retrieve the objects.
public void SetupMainScreen(ParseUser user)
{
var query = ParseObject.GetQuery("GameScore").WhereEqualTo("playerName", user.Username);
query.FindAsync().ContinueWith(t =>
{
IEnumerable<ParseObject> results = t.Result;
List<ParseObject> resultsList = results.ToList();
DealWithResults(resultsList, user);
});
}
public void DealWithResults(List<ParseObject> resultsList, ParseUser me)
{
userGamesPlayed = resultsList[1].Get<int>("GamesPlayed");
userHighestCash = resultsList[2].Get<int>("HighestCash");
userCash = resultsList[3].Get<int>("Cash");
WelcomeText.text = "Welcome, " + me.Username + "\n" +
"Cash: $" + userCash + "\n" +
"Highest Cash: $" + userHighestCash + "\n" +
"Games Played: " + userGamesPlayed;
}
First I tried just making changes to the unity ui from inside the Query but that did not work, So i made an outside function and passed the results to it that way, and that still does not work?
I tried to debug what i was getting in the list with this:
foreach (var res in resultsList)
{
Debug.Log("Class Name = " + res.ClassName + "| Keys are: " + res.Keys);
}
But all it returned was:
Class Name = GameScore| Keys are: System.Collections.Generic.Dictionary`2+KeyCollection[System.String,System.Object]
Can anyone offer any insights?
EDIT2:
ok so first i found results list and its contents
http://i.imgur.com/IKcBbey.png
Then if i open it, it seems to be null ref?
http://i.imgur.com/VmSpi9c.png
But if i go digging, i found the info i need all the way down here
http://i.imgur.com/1Wwu5uc.png
Now just need to work out how to get it?
As there is only one set of data it is always accessible through resultsList[0]. What you want is:
double cash = (double)resultsList[0]["cash"];
string playerName = (string)resultsList[0]["playerName"];
double highestCash = (double)resultsList[0]["HighestCash"];
int gamesPlayed = (int)resultsList[0]["GamesPlayed"];
Though you probably want to check that resultsList is not null and contains one element before you try to dereference it.
Also as your ParseObject appears to be a Dictionary you might find this MSDN page useful.
Ended up solving it.. Much different to the examples...
I had to make a coroutine that called a function on callback to access the variables outside of the query.
I called it with
StartCoroutine(SetupMainScreen(me, DealWithResults));
then called this.
public IEnumerator SetupMainScreen(ParseUser user, Action<GameScore> callback)
{
var query = ParseObject.GetQuery("GameScore").WhereEqualTo("playerName", user.Username).FirstOrDefaultAsync();
while (!query.IsCompleted)
{
yield return null;
}
if (query.IsFaulted || query.IsCanceled)
{
Debug.Log("Getting of GameScores faulted or cancelled...");
}
else
{
var obj = query.Result;
if (obj != null)
callback(new GameScore(obj.Get<int>("cash"),obj.Get<string>("playerName"),obj.Get<int>("HighestCash"),obj.Get<int>("GamesPlayed")));
}
}
public void DealWithResults(GameScore gs)
{
WelcomeText.text = "Welcome, " + gs.Username + "\n" +
"Cash: $" + gs.Cash + "\n" +
"Highest Cash: $" + gs.HighestCash + "\n" +
"Games Played: " + gs.GamesPlayed;
}
And i just made a class to hold the objects.. Hopefully this helps someone else.

Replace char in string not working

I am trying to replace a hash char in a string but the following is not working the
string address = "Blk 344, Jurong West, Street 11, #02-111";
address.Replace("#","%23");
Any ideas guys been driving me crazy
Query String full
http://localhost:54965/SKATEZ/thankyou.aspx?firstname=Fiora&lastname=Ray&address=Blk%20344,%20Jurong%20West,%20Street%2011,%20#02-111&total=22&nirc=S6799954H&country=Singapore&orderid=85&postalcode=746112
I construct the url as follows
string url = "thankyou.aspx?firstname=" + firstname + "&" + "lastname=" + lastname + "&" + "address=" + HttpUtility.EscapeDataString(address) + "&" + "total=" + total + "&" + "nirc=" + tbID.Text + "&" + "country=" + ddlCountry.SelectedValue + "&" + "orderid=" + orderid + "&" + "postalcode=" + tbPostalCode.Text;
Response.Redirect(url);
Try
address = address.Replace("#","%23");
Strings in C# are immutable:
Strings are immutable--the contents of a string object cannot be changed after the object is created, although the syntax makes it appear as if you can do this. For example, when you write this code, the compiler actually creates a new string object to hold the new sequence of characters, and that new object is assigned to b. The string "h" is then eligible for garbage collection.
Using System.Uri.EscapeDataString(string) should fix your issue:
var urlbuilder = new StringBuilder();
urlbuilder.AppendFormat("thankyou.aspx?firstname={0}", firstname);
urlbuilder.AppendFormat("&lastname={0}", lastname);
urlbuilder.AppendFormat("&address={0}", System.Uri.EscapeDataString(address));
urlbuilder.AppendFormat("&total={0}", total);
urlbuilder.AppendFormat("&nirc={0}", tbID.Text);
urlbuilder.AppendFormat("&country={0}", ddlCountry.SelectedValue);
urlbuilder.AppendFormat("&orderid={0}", orderid);
urlbuilder.AppendFormat("&postalcode={0}", tbPostalCode.Text);
Response.Redirect(urlbuilder.ToString());
(using System.Text.StringBuilder to compose your url makes the code a little more readable)

Filling PDF with multiple ASP.NET webforms using iTextSharp

I'm currently building a small website that takes data from 6 different web forms written in ASP.NET and C#. I need all of the information to be written to a PDF at the end of Page 6. I currently have all fields mapped, but each time the page changes, the information gets wiped. i have the information set to pass the values using a query string, but it seems to keep getting lost. Any advice?
EDIT
Sorry for not posting the code the first time, this is my first question i ever posted here. Also, I know my code isn't very efficient, I'm more or less trying to get the grasp of iTextSharp and WebForms. Thanks
Page 1
AcroFields af = ps.AcroFields;
af.SetField("Name", name.Text);
af.SetField("Email", email.Text);
af.SetField("state", state.Text);
af.SetField("city", city.Text);
af.SetField("Address", address.Text);
af.SetField("Phone", phone.Text);
af.SetField("zip", zip.Text);
Response.Redirect("Default.aspx?name=" + this.name.Text + "&Email=" + this.email.Text
+ "&state=" + this.state.Text + "&city=" + this.city.Text + "&Address=" + this.address.Text +
"&Phone=" + this.phone.Text + "&zip=" + this.zip.Text);
Response.Redirect("Page2.aspx");
Page 2
AcroFields af = ps.AcroFields;
af.SetField("Degree", degree.Text);
af.SetField("Grad", gradDate.Text);
af.SetField("Obj", objective.Text);
Response.Redirect("Default.aspx?Degree=" + this.degree.Text + "&Grad=" + this.gradDate.Text
+ "&Obj=" + this.objective.Text);
Response.Redirect("Page3.aspx");
//ps.FormFlattening = true;
Page 3
AcroFields af = ps.AcroFields;
af.SetField("jobStart1", jobStart1.Text);
af.SetField("jobEnd1", jobEnd1.Text);
af.SetField("jobTitle1", jobTitle1.Text);
af.SetField("coName1", coName1.Text);
af.SetField("coAdd1", coAdd1.Text);
af.SetField("Details1", details1.Text);
Response.Redirect("Default.aspx?jobStart1" + this.jobStart1.Text + "&jobEnd1=" + this.jobEnd1.Text
+ "&jobTitle1=" + this.jobTitle1.Text + "&coName1=" + this.coName1.Text + "&coAdd1=" + this.coAdd1.Text +
"&Details1=" + this.details1.Text);
Response.Redirect("Page4.aspx");
Page 4
AcroFields af = ps.AcroFields;
af.SetField("jobStart2", jobStart2.Text);
af.SetField("jobEnd2", jobEnd2.Text);
af.SetField("jobTitle2", jobTitle2.Text);
af.SetField("coName2", coName2.Text);
af.SetField("coAdd2", coAdd2.Text);
af.SetField("Details2", details2.Text);
Response.Redirect("Default.aspx?jobStart2" + this.jobStart2.Text + "&jobEnd2=" + this.jobEnd2.Text
+ "&jobTitle2=" + this.jobTitle2.Text + "&coName2=" + this.coName2.Text + "&coAdd2=" + this.coAdd2.Text +
"&Details2=" + this.details2.Text);
Response.Redirect("Page5.aspx");
Page 5
AcroFields af = ps.AcroFields;
af.SetField("jobStart3", jobStart3.Text);
af.SetField("jobEnd3", jobEnd3.Text);
af.SetField("jobTitle3", jobTitle3.Text);
af.SetField("coName3", coName3.Text);
af.SetField("coAdd3", coAdd3.Text);
af.SetField("Details3", details3.Text);
Response.Redirect("Default.aspx?jobStart3" + this.jobStart3.Text + "&jobEnd3=" + this.jobEnd3.Text
+ "&jobTitle3=" + this.jobTitle3.Text + "&coName3=" + this.coName3.Text + "&coAdd3=" + this.coAdd3.Text +
"&Details3=" + this.details3.Text);
Response.Redirect("Page6.aspx");
Page 6
string name = Request.QueryString["Name"];
string address = Request.QueryString["Address"];
string phone = Request.QueryString["Phone"];
string email = Request.QueryString["Email"];
string city = Request.QueryString["city"];
string state = Request.QueryString["state"];
string zip = Request.QueryString["zip"];
string degree = Request.QueryString["Degree"];
string gradDate = Request.QueryString["Grad"];
string objective = Request.QueryString["Obj"];
string jobStart1 = Request.QueryString["jobStart1"];
string jobEnd1 = Request.QueryString["jobEnd1"];
string jobTitle1 = Request.QueryString["jobTitle1"];
string coName1 = Request.QueryString["coName1"];
string coAdd1 = Request.QueryString["coAdd1"];
string details1 = Request.QueryString["Details1"];
string jobStart2 = Request.QueryString["jobStart2"];
string jobEnd2 = Request.QueryString["jobEnd2"];
string jobTitle2 = Request.QueryString["jobTitle2"];
string coName2 = Request.QueryString["coName2"];
string coAdd2 = Request.QueryString["coAdd2"];
string details2 = Request.QueryString["Details2"];
string jobStart3 = Request.QueryString["jobStart3"];
string jobEnd3 = Request.QueryString["jobEnd3"];
string jobTitle3 = Request.QueryString["jobTitle3"];
string coName3 = Request.QueryString["coName3"];
string coAdd3 = Request.QueryString["coAdd3"];
string details3 = Request.QueryString["Details3"];
AcroFields af = ps.AcroFields;
af.SetField("Name", name);
af.SetField("Email", email);
af.SetField("state", state);
af.SetField("city", city);
af.SetField("Address", address);
af.SetField("Phone", phone);
af.SetField("zip", zip);
af.SetField("Degree", degree);
af.SetField("Grad", gradDate);
af.SetField("Obj", objective);
af.SetField("jobStart1", jobStart1);
af.SetField("jobEnd1", jobEnd1);
af.SetField("jobTitle1", jobTitle1);
af.SetField("coName1", coName1);
af.SetField("coAdd1", coAdd1);
af.SetField("Details1", details1);
af.SetField("jobStart2", jobStart2);
af.SetField("jobEnd2", jobEnd2);
af.SetField("jobTitle2", jobTitle2);
af.SetField("coName2", coName2);
af.SetField("coAdd2", coAdd2);
af.SetField("Details2", details2);
af.SetField("jobStart3", jobStart3);
af.SetField("jobEnd3", jobEnd3);
af.SetField("jobTitle3", jobTitle3);
af.SetField("coName3", coName3);
af.SetField("coAdd3", coAdd3);
af.SetField("Details3", details3);
af.SetField("Skills", skills.Text);
ps.FormFlattening = true;
}
Response.End();
Response.Redirect("Default.aspx?name=" + this.name.Text + "&Email=" + this.email.Text
+ "&state=" + this.state.Text + "&city=" + this.city.Text + "&Address=" + this.address.Text +
"&Phone=" + this.phone.Text + "&zip=" + this.zip.Text);
Response.Redirect("Page2.aspx"); //this will never be reached because the line before it ends the current execution context
You're redirecting back to Default.aspx, but judging by your question the intention is to go to Page2.aspx. But Response.Redirect("Page2.aspx"); is never reached because the response ends after the first redirect. When you call response redirect (the standard overload) the current request context ends, the client is sent an HTTP redirect. So no further code will be executed.
Instead, replace both of those lines with this one:
Response.Redirect("Page2.aspx?name=" + this.name.Text + "&Email=" + this.email.Text
+ "&state=" + this.state.Text + "&city=" + this.city.Text + "&Address=" + this.address.Text +
"&Phone=" + this.phone.Text + "&zip=" + this.zip.Text);
Then on Page 2, you'll need code in Page_Load to pull the values out of the request query string, and additional code so that when you leave the page you pass the values from page 1 and the new values from page 2. And so on.
You should UriEncode your values before putting them in the query string. And concatenating a bunch of strings is really ugly. Perhaps a format string would be appropriate here.
Also, if I were you, I'd abandon the query string approach entirely. That's really messy, passing them around like that because after several pages, you're going to have a ton of parameters and it's going to be a messy URL and a lot of boilerplate code. And neither of those is good. Instead, you should create a Model to represent all the information you want to gather, then store the model somewhere such as Session to pass it between pages. On the function where you build your PDF, have it accept the model as a parameter and generate the PDF according to the values in your model.
The model is simply a C# class that represents the values your PDF needs. For example, here's a starting point:
public class ApplicantInformationModel
{
public string Name {get; set;}
public string Email {get; set;}
public List<Job> Jobs {get; set;}
public string PhoneNumber {get; set;}
}
public class Job
{
public DateTime StartDate {get; set;}
public DateTime EndDate {get; set;}
public string Title {get; set;}
public string Company {get; set;}
}
Your PDF creation function will accept this:
public static Document GeneratePdfForApplicant(ApplicantInformationModel model)
{
//use iTextSharp to generate and return PDF based on the model
}

Payment succeeds, and our data matches querystring data, but falls thru to INVALID anyway!

Why does my ipn script I wrote always fail? It always goes to INVALID even though it matches everything in the query string that paypal sends to me?
notification.cshtml?tx=b78v54b5b55rby92S&st=Completed&amt=3.04&cc=USD&cm=&item_number=&merchant_return_link=Return+to+web+site+name&form_charset=UTF-8
And the part that checks it is:
string LiveURL = "https://www.paypal.com/cgi-bin/webscr";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(LiveURL);
// Set request back values.
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
byte[] parameters = Request.BinaryRead(HttpContext.Current.Request.ContentLength);
string RequestString = System.Text.Encoding.ASCII.GetString(parameters);
RequestString += "&cmd=_notify-validate";
request.ContentLength = RequestString.Length;
// Send request to PP and get response.
StreamWriter Sout = new StreamWriter(request.GetRequestStream(), System.Text.Encoding.ASCII);
Sout.Write(RequestString);
Sout.Close();
StreamReader Sin = new StreamReader(request.GetResponse().GetResponseStream());
string response = Sin.ReadToEnd();
Sin.Close();
if(result != null && result.OrderStatus == "Confirmed")
{
switch(response)
{
case "VERIFIED":
if(Request["st"] == "Completed")
{
var PPQuery = "SELECT TransactionId, OrderTotal FROM Orders WHERE OrderId = '" + Session["OSFOID"] + "' AND UserId = '" + WebSecurity.CurrentUserId + "'";
var ppQueryResult = database.Query(PPQuery);
foreach(var item in ppQueryResult)
{
decimal fff = 3.04M;
if(item["TransactionId"] != Request["tx"])
{
if(item["OrderTotal"] == TotalPrice)
{
// Payment was a success. Convey that to the user.
output = "Thanks. Order complete.";
}
else
{
// Possible fraud. Log it.
}
}
else
{
// This is a duplicate transaction. Log it and Redirect to homepage.
}
}
}
break;
case "INVALID":
output = "Invalid was returned. Investigate further.";
break;
default:
output = "Other exception has occured. Investigate further and log.";
break;
}
}
The code looks fine. The problem must be with response not matching "VERIFIED".
You're not in Turkey by chance, and changing response to uppercase prior to the comparison? *
*) If the locale is Turkey, uppercasing a string turns i into İ, not I (just one of the many traps with string manipulation)
Within the "VERIFIED" block, check:
if (Request.Params["payment_status"] == "Completed")
{
...
}
Request["st"] is incorrect.
Be sure to set IPN URL in one place in PayPal admin and do not use the other form of return URL checking (can't remember the name of it offhand) and IPN at the same time.
There is no "merchant_return_link" parameter; I think it should be "notify_url"... the URL string and the list of params doesn't look right to me; for example: &cm=&item_number
I know your list of params will be unique for your situation, but here's some sample code where I construct the URL to be passed to PayPal:
protected string GetPayPalURL(string SERVER_URL, string business, string[] itemNames,
int[] quantities, decimal[] amounts, double[] weight, string invoiceID, string transID, string NOTIFY_URL)
{
// Customer will be required to specify delivery address to PayPal - VERY IMPORTANT
const string NO_SHIPPING = "2";
StringBuilder url = new StringBuilder();
url.Append(SERVER_URL + "?cmd=_cart&upload=1");
url.Append("&business=" + HttpUtility.UrlEncode(business));
for (int i = 0; i < itemNames.Length; i++)
{
url.Append("&item_name" + "_" + (i + 1).ToString() + "=" + HttpUtility.UrlEncode(itemNames[i]));
url.Append("&quantity" + "_" + (i + 1).ToString() + "=" + quantities[i].ToString().Replace(",", "."));
url.Append("&amount" + "_" + (i + 1).ToString() + "=" + amounts[i].ToString().Replace(",", "."));
url.Append("&weight" + "_" + (i + 1).ToString() + "=" + weight[i].ToString().Replace(",", "."));
}
url.Append("&no_shipping=" + HttpUtility.UrlEncode(NO_SHIPPING));
url.Append("&custom=" + HttpUtility.UrlEncode(invoiceID));
url.Append("&txn_id=" + HttpUtility.UrlEncode(transID));
url.Append("&notify_url=" + HttpUtility.UrlEncode(NOTIFY_URL));
return url.ToString();
}
I think the Paypal method you are trying to do is as follows on code project
and if you get payment_status = INVALID, then check the reason in payment_reason
i dont see in the code where you are defining result which is checked in the if, also in the switch you are checking against request, surely this should be against response?

How to call a JavaScript function multiple times in a loop on page reload with ASP.NET

I'm using the local database functionality in Chrome and Safari and what I do when I want to save this to a remote database is to create a hidden textfield and then using JSON to stringify each row. In the code behind I then parse each JSON object and insert it into the list. What I want to do now is to delete these rows from the local database. I have a JavaScript function called deletePatient:
function deletePatient(patientID) {
MaRDB.transaction(
function (transaction) {
transaction.executeSql("DELETE FROM Patients WHERE id = " + patientID + ";");
}
);
}
I then call this function from the code behind if the insert was successfull
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "Delete", "<script language='javascript'>$(document).ready(function() {deletePatient(" + id + ");});</script>");
However, it only deletes the patient with the lowest ID (the first JSON object). When I step through the code it goes back to that code for each ID but only deletes one. If I try with an alert it also only shows one ID even though it iterates through the code N number of times. I guess it's some kind of conflict with postback and executing a JavaScript function here but is it possible to solve?
protected void btnSave_Click(object sender, EventArgs e)
{
bool successfullySent = false;
SharePointConnection();
int count = Convert.ToInt32(txtRows.Text);
for (int i = 0; i <= count; i++)
{
string p = String.Format("{0}", Request.Form["hiddenField" + i]).ToString();
JObject o = JObject.Parse(p);
id = (int)o["id"];
string name = (string)o["name"];
string address = (string)o["address"];
string city = (string)o["city"];
string state = (string)o["state"];
string zip = (string)o["zip"];
string country = (string)o["country"];
string phone = (string)o["phone"];
StringBuilder sb_method = new StringBuilder();
sb_method.Append("<Method ID='1' Cmd='New'>");
sb_method.Append("<Field Name='Title'>" + name + "</Field>");
sb_method.Append("<Field Name='Address'>" + address + "</Field>");
sb_method.Append("<Field Name='City'>" + city + "</Field>");
sb_method.Append("<Field Name='State'>" + state + "</Field>");
sb_method.Append("<Field Name='ZIP'>" + zip + "</Field>");
sb_method.Append("<Field Name='Country'>" + country + "</Field>");
sb_method.Append("<Field Name='Phone'>" + phone + "</Field>");
sb_method.Append("</Method>");
XmlDocument x_doc = new XmlDocument();
XmlElement xe_batch = x_doc.CreateElement("Batch");
xe_batch.SetAttribute("OnError", "Continue");
xe_batch.InnerXml = sb_method.ToString();
try
{
//updating the list
XmlNode xn_return = listsObj.UpdateListItems(ConfigurationManager.AppSettings["SaveToSPList"].ToString(), xe_batch);
if (xn_return.InnerText == "0x00000000")
{
successfullySent = true;
}
else
{
successfullySent = false;
}
}
catch
{
successfullySent = false;
}
if (successfullySent)
{
divSuccessfulMessage.Visible = true;
lblSuccessfulMessage.Text = "Report Successfully Saved";
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "Delete", "<script language='javascript'>$(document).ready(function() {deletePatient(" + id + ");});</script>");
}
else
{
divErrorMessage.Visible = true;
lblErrorMessage.Text = "Failed to Save, Please Try Again";
}
}
}
Thanks in advance.
I'm assuming you're calling the RegisterClientScriptBlock multiple times? In that case, the second parameter of your RegisterClientScriptBlock is the unique key of the script you're trying to inject. Since its always the same, in effect you're basically 'overwriting' each previous script with the latest one.
Try it again, and make sure your key is unique every time you call the RegisterClientScriptBlock (for example, append a counter to it?).
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "Delete" + counter.ToString(), "<script language='javascript'>$(document).ready(function() {deletePatient(" + id + ");});</script>");

Categories

Resources