public static void MakeFullGridRowClickable(GridViewRow row, ClientScriptManager clientScriptManager) { if (row.RowType == DataControlRowType.DataRow) { // Get the LinkButton control in the first cell LinkButton _singleClickButton = (LinkButton)row.Cells[0].Controls[0]; // Get the javascript which is assigned to this LinkButton string _jsSingle = clientScriptManager.GetPostBackClientHyperlink(_singleClickButton, ""); // To prevent the first click from posting back immediately // (therefore giving the user a chance to double click) // pause the postbackfor 300 milliseconds by // wrapping the postback command in a setTimeout _jsSingle = _jsSingle.Insert(11, "setTimeout(\""); _jsSingle += "\", 300)"; // Add this javascript to the onclick Attribute of the row row.Attributes["onclick"] = _jsSingle; // Get the LinkButton control in the second cell LinkButton _doubleClickButton = (LinkButton)row.Cells[1].Controls[0]; // Get the javascript which is assigned to this LinkButton string _jsDouble = clientScriptManager.GetPostBackClientHyperlink(_doubleClickButton, ""); // Add this javascript to the ondblclick Attribute of the row row.Attributes["ondblclick"] = _jsDouble; } }
protected void GridView_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { bool isOwner = IsOwner(DataBinder.Eval(e.Row.DataItem, "Owner").ToString()); // display action buttons if user is owner TableCell actionCell = e.Row.Cells[e.Row.Cells.Count - 1]; actionCell.FindControl("btn_del").Visible = isOwner; bool quizzTaken = !(e.Row.Cells[1].Text.Equals(" ")); // pour le NULL // project detail on row click, except for the last cell with the action buttons // Only if the quizz has not been done yet if (!quizzTaken) { for (int i = 0; i < e.Row.Cells.Count - 1; i++) { e.Row.Cells[i].Attributes["onclick"] = clientScript.GetPostBackClientHyperlink(GridView_Projects, "Select$" + e.Row.RowIndex); e.Row.Cells[i].Attributes.Add("style", "cursor: pointer"); } } e.Row.Attributes.Add("IdQuizz", DataBinder.Eval(e.Row.DataItem, "IdQuizz").ToString()); } }
public void ClientScriptManager_GetPostBackClientHyperlink() { MyPage p = new MyPage(); ClientScriptManager cs = p.ClientScript; String hyperlink = cs.GetPostBackClientHyperlink(p, "args1"); Assert.IsTrue(hyperlink.IndexOf("javascript:") != -1, "GetPostBackClientHyperlink_javaScript"); Assert.IsTrue(hyperlink.IndexOf(p.ClientID) != -1, "GetPostBackClientHyperlink_targetEvent"); Assert.IsTrue(hyperlink.IndexOf("args1") != -1, "GetPostBackClientHyperlink_targetArgs"); }
public static void AddDoubleClickAttributeToGridDataBound(ClientScriptManager manager, GridView grid, GridViewRowEventArgs e) { if (e.Row.RowType != DataControlRowType.DataRow) { return; } LinkButton dblClickButton = (LinkButton)e.Row.Cells[0].Controls[0]; string script = manager.GetPostBackClientHyperlink(dblClickButton, ""); e.Row.Attributes["ondblclick"] = script; manager.RegisterForEventValidation(e.Row.UniqueID + "$ctl00"); }
/// <summary> /// добавление двойного клика. считаем что кнонпка с двойным кликом идёт первой в списке колонок грида /// </summary> /// <param name="manager"></param> /// <param name="grid"></param> public static void AddDoubleClickAttributeToGrid(ClientScriptManager manager, GridView grid) { foreach (GridViewRow r in grid.Rows) { if (r.RowType == DataControlRowType.DataRow) { LinkButton dblClickButton = (LinkButton)r.Cells[0].Controls[0]; string script = manager.GetPostBackClientHyperlink(dblClickButton, ""); r.Attributes["ondblclick"] = script; manager.RegisterForEventValidation(r.UniqueID + "$ctl00"); } } }
string GetClientEvent(Menu owner, MenuItem item) { if (owner == null) { owner = Owner; } Page page = owner.Page; ClientScriptManager csm = page != null ? page.ClientScript : null; if (csm == null) { return(String.Empty); } return(csm.GetPostBackClientHyperlink(owner, item.Path, true)); }
protected void GridView_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { bool isOwner = IsOwner(DataBinder.Eval(e.Row.DataItem, "OwnerId").ToString()); // display action buttons if user is owner TableCell actionCell = e.Row.Cells[e.Row.Cells.Count - 1]; actionCell.FindControl("btn_edit").Visible = isOwner; actionCell.FindControl("btn_del").Visible = isOwner; // project detail on row click, except for the last cell with the action buttons for (int i = 0; i < e.Row.Cells.Count - 1; i++) { e.Row.Cells[i].Attributes["onclick"] = clientScript.GetPostBackClientHyperlink(GridView_Projects, "Select$" + e.Row.RowIndex); e.Row.Cells[i].Attributes.Add("style", "cursor: pointer"); } e.Row.Attributes.Add("idProject", DataBinder.Eval(e.Row.DataItem, "IdProject").ToString()); } }
protected override void RenderAttributes(HtmlTextWriter writer) { // we don't want to render the "user" URL, so we either render: EventHandler serverClick = (EventHandler)Events [serverClickEvent]; if (serverClick != null) { ClientScriptManager csm; #if NET_2_0 // a script PostBackOptions options = GetPostBackOptions(); csm = Page.ClientScript; csm.RegisterForEventValidation(options); Attributes ["href"] = csm.GetPostBackEventReference(options, true); #else // a script csm = new ClientScriptManager(Page); Attributes ["href"] = csm.GetPostBackClientHyperlink(this, String.Empty); #endif } else { string hr = HRef; if (hr != string.Empty) #if TARGET_J2EE { // For J2EE portlets we need to genreate a render URL. HRef = ResolveClientUrl(hr, String.Compare(Target, "_blank", StringComparison.InvariantCultureIgnoreCase) != 0); } #else { HRef = ResolveClientUrl(hr); } #endif } base.RenderAttributes(writer); // but we never set back the href attribute after the rendering // nor is the property available after rendering Attributes.Remove("href"); }
public void dgAttendance_ItemDataBound(object sender, DataGridItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { if (dgAttendance.EditItemIndex == -1) { ClientScriptManager csm = Page.ClientScript; DataRowView drv = (DataRowView)e.Item.DataItem; Control holder = (PersonDetailPageID == -1 ? e.Item.Controls[1] : e.Item.Controls[0]); Control hover = holder.Controls[1]; LinkButton lbReprint = (LinkButton)holder.Controls[3]; LinkButton lbPost = (LinkButton)holder.Controls[5]; String html = "", securityNumber; Boolean hasCCCEV = false; try { String arenaBin; Assembly asm; // // Find the location of the Arena bin directory and then try to load // the Cccev assembly file. // arenaBin = new Organization().GetType().Assembly.CodeBase.Split(new string[] { "/Arena." }, StringSplitOptions.None)[0]; asm = System.Reflection.Assembly.LoadFrom(arenaBin + "/Arena.Custom.Cccev.CheckIn.dll"); if (asm != null) { hasCCCEV = true; } } catch { } // // Add the link to the person. // if (PersonDetailPageID != -1) { ((LinkButton)hover).Attributes["href"] = "default.aspx?page=" + PersonDetailPageID.ToString() + "&guid=" + drv["guid"]; } // // If we have the CCCEV check-in library, provide a re-print button. // if (hasCCCEV && LabelPrintProviderID != -1) { html += "<span class=\"smallText\"><a href=\"" + csm.GetPostBackClientHyperlink(lbReprint, null) + "\">Reprint</a> labels for " + drv["first_name"] + "<br /></span>"; html += "<br />"; } // // If we have a topic area, provide a post/remove security number. // if (TopicAreaID != -1 && drv["security_code"].ToString().Length > 2) { // // Check if the security code is already posted. // securityNumber = drv["security_code"].ToString().Substring(2).Trim(); if (FindPromotionRequest(Convert.ToInt32(drv["occurrence_attendance_id"])) != -1) { html = html + "<span class=\"smallText\">Remove security number <a href=\"" + csm.GetPostBackClientHyperlink(lbPost, null) + "\">" + securityNumber + "</a><br /></span>"; } else { html = html + "<span class=\"smallText\">Post security number <a href=\"" + csm.GetPostBackClientHyperlink(lbPost, null) + "\">" + securityNumber + "</a><br /></span>"; } } html = html.Replace("'", "\\'"); ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "hover" + hover.ClientID, "$(document).ready(function() {popupOverObject('" + hover.ClientID + "', '" + html + "');});", true); } } }
protected override void RenderAttributes (HtmlTextWriter writer) { // we don't want to render the "user" URL, so we either render: EventHandler serverClick = (EventHandler) Events [serverClickEvent]; if (serverClick != null) { ClientScriptManager csm; #if NET_2_0 // a script PostBackOptions options = GetPostBackOptions (); csm = Page.ClientScript; csm.RegisterForEventValidation (options); Attributes ["href"] = csm.GetPostBackEventReference (options, true); #else // a script csm = new ClientScriptManager (Page); Attributes ["href"] = csm.GetPostBackClientHyperlink (this, String.Empty); #endif } else { string hr = HRef; if (hr != string.Empty) #if TARGET_J2EE // For J2EE portlets we need to genreate a render URL. HRef = ResolveClientUrl (hr, String.Compare (Target, "_blank", StringComparison.InvariantCultureIgnoreCase) != 0); #else HRef = ResolveClientUrl (hr); #endif } base.RenderAttributes (writer); // but we never set back the href attribute after the rendering // nor is the property available after rendering Attributes.Remove ("href"); }
/// <summary> /// Gets a reference, with javascript: appended to the beginning of it, that can be used in a client event to post back to the server for the specified control and with the specified event arguments. /// </summary> /// <returns> /// A string representing a JavaScript call to the postback function that includes the target control's ID and event arguments. /// </returns> /// <param name="control">The server control to process the postback . /// </param><param name="argument">The parameter passed to the server control. /// </param> public string GetPostBackClientHyperlink(IControl control, string argument) { ArgumentUtility.CheckNotNullAndType <Control> ("control", control); return(_clientScriptManager.GetPostBackClientHyperlink((Control)control, argument)); }