Calling Thickbox popup from Parent Page ServiceTicket.aspx like this :
function OpenCustomerView(companyID, accountID) {
var e = document.getElementById('<%= txtAccountID.ClientID %>');
var custId = e.value;
**var url = "CustomerSearch.aspx?custid=" + custId + "&TB_iframe=true&width=1200&height=800";**
**tb_show("Customer Search", url);**
}
And on Child Popup Window CustomerSearch.aspx i m using this code to close the popup and sending values back to parent :
function CloseDialog(tanksize,companyID, accountID, address, serviceContract, cod, divisionId) {
**var url = 'ServiceTicket.aspx?CompanyID=' + companyID + '&AccountID=' + accountID + '&Address=' + address.replace('#', '%23') + '&TankSize=' + tanksize + '&divisionId=' + divisionId;**
}
in above line var url='ServiceTicket.aspx?CompanyID=' this is how i m passing values to parent window.
Handling values on Parent Page with C# Code behind
if (Request.QueryString["companyID"] != null && Request.QueryString["companyID"] != "")
{
short companyID = Convert.ToInt16(Request.QueryString["companyID"]);
}
So I need help in closing this child popup from function CloseDialog and passing values to parent by that var url used in the closedialog function.Please guide me or share your code...
Not sure if this will work or not as it was a way long back I did something like this for similar issue. Just give try and see if works out else notify here will update again.
function CloseDialog(tanksize,companyID, accountID, address, serviceContract, cod, divisionId) {
tb_remove();
var url = 'ServiceTicket.aspx?CompanyID=' + companyID + '&AccountID=' + accountID + '&Address=' + address.replace('#', '%23') + '&TankSize=' + tanksize + '&divisionId=' + divisionId;
window.parent.location.href = url;
}
Related
old school c# developer here..
long story short, the company I'm working for has decided to continue developing using core technology and as a former winforms developer I'm not familiar with the web concepts and having trouble saving the details table to the master table. Any help is very appreciated.
I have two Tables with 1 to many Relationship
TOURNAMENTS_M (Master)
TOURNAMENTS_D (Detail)
I have edited the scaffolded Create page to include the fields for the detail table for entry.
I have even managed to update the table(visually) for the added details records using Jquery.
I'm having trouble to save this information to my database though, there have been a couple of different tutorials I've been following to with different approaches.. yet could't manage to succeed using neither approaches...
1st Approach is using Jquery and Ajax method. I've seen examples where people save data through a modal window and when save is clicked the data is updated on the gridview so as I understood(correct me if I'm wrong) Ajax is used to reload data without refreshing the page, and to postback the data to the controller. In my case I'm no sure if this is the right method to use since both master and child controls are on the same page.
2nd Approach is using just Jquery
in this approach my Create method in the controller and jquery methods are as following
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Create(TOURNAMENTS_M pTournamentsM)
{
if (ModelState.IsValid)
{
_context.Add(pTournamentsM);
await _context.SaveChangesAsync();
return RedirectToAction(nameof(Index));
}
return View(pTournamentsM);
}
function GetCurrentDetail() {
var TD_LEVEL = $("#TD_LEVEL").val();
var TD_SB = $("#TD_SB").val();
var TD_BB = $("#TD_BB").val();
var tourDetail = {
"TD_LEVEL": TD_LEVEL,
"TD_SB": TD_SB,
"TD_BB": TD_BB
};
return tourDetail;
}
//triggers when clicked on add tour details button
function CreateRowForTourDetails() {
var current = GetCurrentDetail();
var index = $("#detailsTable").children("tr").length;
var indexcell = "<td style='display:none'> <input type='hidden' id='index" + index + "' name='TOURNAMENTS_D.index' value = '" + index + "' /> </td>";
var TD_LEVEL = "<td> <input type='hidden' id='TD_LEVEL" + index + "' name='TOURNAMENTS_D[" + index + "].TD_LEVEL ' value = '" + current.TD_LEVEL + "' />" + current.TD_LEVEL + " </td>";
var TD_SB = "<td> <input type='hidden' id='TD_SB" + index + "' name='TOURNAMENTS_D[" + index + "].TD_SB ' value = '" + current.TD_SB + "' />" + current.TD_SB + " </td>";
var TD_BB = "<td> <input type='hidden' id='TD_BB" + index + "' name='TOURNAMENTS_D[" + index + "].TD_BB ' value = '" + current.TD_BB + "' />" + current.TD_BB + " </td>";
//var removeButton = "<td><a id ='myRemove' data-itemId='0' class='btn btn-primary'>Remove</a></td>";
var tourDetail = "<tr>" +indexcell + +TD_LEVEL + TD_SB + TD_BB + "</tr>";
var detailsTableBody = $("#DetailsTableBody");
detailsTableBody.append(tourDetail);
}
with this method when I place my break point inside the Create function in my controller I can see that the count of TOURNAMENTS_D increases however the value is null
Try Web Browser Debug tool to check the request, make sure your request like below:
Here is My Model:
public class Order
{
public int Id { get; set; }
public string OrderNo { get; set; }
public ICollection<OrderDetail> OrderDetails { get; set; }
}
public class OrderDetail
{
public int Id { get; set; }
public int ProductId { get; set; }
}
I'm trying to automate a website, and I have the following piece of code to change the value of a dropdown (select):
private bool ChangeElementSelection(mshtml.IHTMLDocument3 document, string id, string value)
{
var el = document.getElementById(id);
if (el != null)
{
log.Write("Setting HTML element " + id + " value to " + value + " (by ID)");
el.setAttribute("value", value);
var el3 = (el as IHTMLElement3);
el3.FireEvent("onchange");
return true;
}
log.Write("Could not find HTML element " + id + " (by ID)");
return false;
}
The website I am visiting uses JQuery to catch the "change" event for the select element. It does not expect any parameters. Yet the script is not triggered. Why ?
I have the following case but i don't know how to do it .
I have a page say [page1.aspx] this page have a button in the event click of this button i call a method in web service , this method need a url as a param , every thing goes okay and the receiver ,receive the url ,but when clicks on that link ,it redirects to the login page instead of the sent page !! How to open the sent page which has sessions in a secure manner ?
protected void SendNotification(int StateSerial)
{
DataTable dt = Utilities.GetStateUsers(StateSerial, taskCode);
if (dt != null && dt.Rows.Count > 0)
{
string message = Session["TransDes"].ToString().Trim();
string sender = Session["send"].ToString().Trim();
string sys_code = "SM" + "|" + taskCode.ToString();
string sys_name = Task.GetTask(taskCode).Rows[0]["task_name"].ToString();
for (int i = 0; i < dt.Rows.Count; i++)
{
string emp_num = dt.Rows[i][0].ToString();
string serial = taskCode.ToString() + "|" + obj.TransSerial + "|" + obj.TransYear;
}
string URL_inbox = "https://..../Page1.aspx?TCode=" + taskCode + "&TransSerial=" + obj.TransSerial + "&TransYear=" + obj.TransYear + "&mainCode=" + obj.MainCode + "&year=" + obj.Year + "&MCode=" + obj.MainCode + "&DYear=" + obj.Year + "&AR=1";
Service1 noti = new Service1();
string res = noti.sendNotification(emp_num, message, URL_inbox, sender, serial, sys_code, sys_name);
}
}
}
Now the user receive the URL_inbox but when clicks on it it redirects to the login page instead
because the following code is in the page load of Page1.aspx
if (Session["emp_num"] != null && !string.IsNullOrEmpty(Session["emp_num"].ToString()))
{
emp_numb = int.Parse(Session["emp_num"].ToString());
}
else
{
Response.Redirect("https://..../LoginPage.aspx");
}
How to handle this problem in secure manner ?
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>
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>");