I am using rad menu (telerik) in my website. the menu items are binding to menu in code behind. i take the navigate URL from database and the navigate URL will be sometimes a JavaScript like
js=OpenSupportWin();
Instead of page url.
So when I give this to navigateurl nothing is happening. please help me to solve this.
private void GenerateVerticalMenuTelerik(string pParentMenuId, RadMenuItem rmi)
{
List<DBMenus> ListVerticalMenus = new List<DBMenus>();
ListVerticalMenus = MenuGenerator.GetVerticalMainMenusFromNode(pParentMenuId, ClsLogin.Instance.IsAuthenticated());
if (ListVerticalMenus != null)
{
foreach (DBMenus asVertical in ListVerticalMenus)
{
try
{
bool IsSelectedVertical = (m_SelectedMenuPath.SelectedSubItemId == asVertical.SiteMapNodeId);
RadMenuItem rmItem = new RadMenuItem();
rmItem.Text = asVertical.WORDINGTextTitle;
rmItem.NavigateUrl = PII.ToolWeb.Tools.pkFunctions.GetPageLinkURL(asVertical.SiteMapNodeUrl);
rmi.Items.Add(rmItem);
}
catch (Exception ex)
{
}
}
}
}
string url_js = asVertical.SiteMapNodeUrl;
if (url_js.Contains("js"))
{
url_js = url_js.Replace("?js=", "");
url_js = url_js.Replace(";", "");
url_js = "javascript:" + url_js;
}
i wrote these lines of code and it works for me
Set your navigateUrl to something like this:
item.NavigateUrl = "javascript:OpenSupportWin();";
Related
I'm using Xamarin.Forms and I am trying to convert an html string to a pdf file using EvoPdfConverter, but the problem is that when I try to do so, on the line htmlToPdfConverter.ConvertHtmlToFile(htmlData, "", myDir.ToString()); in the code snippet below, the app just freezes and does nothing, seems like it wants to connect to the given IP, but it can't, however I don't get any errors or exceptions! not even catch!! does anybody know what I should do to resolve this issue? and here is my code for this:
public void ConvertHtmlToPfd(string htmlData)
{
ServerSocket s = new ServerSocket(0);
HtmlToPdfConverter htmlToPdfConverter = new
HtmlToPdfConverter(GetLocalIPAddress(),(uint)s.LocalPort);
htmlToPdfConverter.TriggeringMode = TriggeringMode.Auto;
htmlToPdfConverter.PdfDocumentOptions.CompressCrossReference = true;
htmlToPdfConverter.PdfDocumentOptions.PdfCompressionLevel = PdfCompressionLevel.Best;
if (ContextCompat.CheckSelfPermission(Android.App.Application.Context, Manifest.Permission.WriteExternalStorage) != Permission.Granted)
{
ActivityCompat.RequestPermissions((Android.App.Activity)Android.App.Application.Context, new String[] { Manifest.Permission.WriteExternalStorage }, 1);
}
if (ContextCompat.CheckSelfPermission(Android.App.Application.Context, Manifest.Permission.ReadExternalStorage) != Permission.Granted)
{
ActivityCompat.RequestPermissions((Android.App.Activity)Android.App.Application.Context, new String[] { Manifest.Permission.ReadExternalStorage }, 1);
}
try
{
// create the HTML to PDF converter object
if (Android.OS.Environment.IsExternalStorageEmulated)
{
root = Android.OS.Environment.ExternalStorageDirectory.ToString();
}
htmlToPdfConverter.LicenseKey = "4W9+bn19bn5ue2B+bn1/YH98YHd3d3c=";
htmlToPdfConverter.PdfDocumentOptions.PdfPageSize = PdfPageSize.A4;
htmlToPdfConverter.PdfDocumentOptions.PdfPageOrientation = PdfPageOrientation.Portrait;
Java.IO.File myDir = new Java.IO.File(root + "/Reports");
try
{
myDir.Mkdir();
}
catch (Exception e)
{
string message = e.Message;
}
Java.IO.File file = new Java.IO.File(myDir, filename);
if (file.Exists()) file.Delete();
htmlToPdfConverter.ConvertHtmlToFile(htmlData, "", myDir.ToString());
}
catch (Exception ex)
{
string message = ex.Message;
}
}
Could you try to set a base URL to ConvertHtmlToFile call as the second parameter? You passed an empty string. That helps to resolve the relative URLs found in HTML to full URLs. The converter might have delays when trying to retrieve content from invalid resources URLs.
is it possible to modify a session from a webmethod, well the complete description is,
I have a button that client side triggered to add data from textboxes into one new row inside a session
The session declared as
public List<Some_Business_Object_Here> A_Session
{
get
{
return (List<Some_Business_Object_Here>)Session["Session_Name_Here"];
}
set
{
Session["Session_Name_Here"] = value;
}
}
and The WebMethod
[WebMethod]
public static string InsertItemDt(List<string> dataIns)
{
BOResponse objRes = new BOResponse();
SomeFormHere form = new SomeFormHere();
Some_Business_Object_Here objDet = new Some_Business_Object_Here();
objDet.Data1 = dataIns[0];
objDet.Data2 = Convert.ToInt32(dataIns[1]);
objDet.Data3 = Convert.ToDecimal(dataIns[2]);
objRes = form.A_Processing_Method(objDet, ListItemDetail);
return new JavaScriptSerializer().Serialize(objRes);
}
and if the method processing to add a new row after some validation
is it possible to do it with this kind of method?
Edit: BOResponse is object for validation, containing only error code and catch error message
so the method be like
Private BOResponse A_Processing_Method (Some_Business_Object_Here obj)
{
try
{
(Some Validation Here...)
if (!validation)
{
MsgCode = 10;
MsgDesc = "Some Custom Error Text Here"
}
else
{
A_Session.Add(obj);
}
}
catch (Exception err)
{
MsgCode = 20;
MsgDesc = err.Message;
}
}
nevermind, seems it's working this way
I need to make some of the NavigationMenu items visible only to some users.
In my case I need to make 2 of them available only to admin.
I searched google and I found a command which works :
NavigationMenu.Items.Remove(NavigationMenu.FindItem("HERE GOES THE NAME OF THE MENU I NEED TO REMOVE"));
Till here,everything is ok.
But which command do I need to use to make it available again ?
Please help me. Thnx in advance ;)
public partial class SiteMaster : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
NavigationMenu.Items.Remove(NavigationMenu.FindItem("Employers"));
if (Matrix.UserLoggedId == Guid.Empty)
{
hlLogin.Visible = true;
lblUsername.Visible = false;
lnkLogout.Visible = false;
}
else
{
// here goes the code to add the menu
hlLogin.Visible = false;
lblUsername.Visible = true;
lnkLogout.Visible = true;
Marin.Employee.DetailsDataTable emp = Matrix.GetEmployeeByUniqueId(Matrix.UserLoggedId);
if (emp.Rows.Count > 0)
{
lblUsername.Text = emp.Rows[0]["Firstname"].ToString();
bool isAdmin =Convert.ToBoolean(emp.Rows[0]["isAdmin"]);
if (isAdmin)
{
//here goes the code to show the menu
}
else
{
NavigationMenu.Items.Remove(NavigationMenu.FindItem("Employers"));
}
}
}
}
Try this, replace x with correct values.
var mi = new MenuItem(x,x,x,x)
NavigationMenu.Items.Add(mi);
For more info on MenuItem check this -
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.menuitem.aspx
I am developing a sharepoint 2007 web part that uses custom properties. Here is one:
[Personalizable(PersonalizationScope.User), WebDisplayName("Policy Update List Name")]
[WebDescription("The name of the SharePoint List that records all the policy updates.\n Default value is Policy Updates Record.")]
public string PolicyUpdateLogName
{
get { return _PolicyUpdateLogName == null ? "Policy Updates Record" : _PolicyUpdateLogName; }
set { _PolicyUpdateLogName = value; }
}
The properties work fine except that the changes are not reflected in the web part until you leave the page and navigate back (or just click on the home page link). Simply refreshing the page doesn't work, which makes me think it has something to do with PostBacks.
My current theory is that the ViewState is not loading postback data early enough for the changes to take effect. At the very least, the ViewState is involved somehow with the issue.
Thanks,
Michael
Here is more relevant code:
protected override void CreateChildControls()
{
InitGlobalVariables();
FetchPolicyUpdateLog_SPList();
// This function returns true if the settings are formatted correctly
if (CheckWebPartSettingsIntegrity())
{
InitListBoxControls();
InitLayoutTable();
this.Controls.Add(layoutTable);
LoadPoliciesListBox();
}
base.CreateChildControls();
}
...
protected void InitGlobalVariables()
{
this.Title = "Employee Activity Tracker for " + PolicyUpdateLogName;
policyColumnHeader = new Literal();
confirmedColumnHeader = new Literal();
pendingColumnHeader = new Literal();
employeesForPolicy = new List<SPUser>();
confirmedEmployees = new List<SPUser>();
pendingEmployees = new List<SPUser>();
}
...
// uses the PolicyUpdateLogName custom property to load that List from Sharepoint
private void FetchPolicyUpdateLog_SPList()
{
site = new SPSite(siteURL);
policyUpdateLog_SPList = site.OpenWeb().GetList("/Lists/" + PolicyUpdateLogName);
}
...
protected void InitListBoxControls()
{
// Init ListBoxes
policies_ListBox = new ListBox(); // This box stores the policies from the List we loaded from SharePoint
confirmedEmployees_ListBox = new ListBox();
pendingEmployees_ListBox = new ListBox();
// Postback & ViewState
policies_ListBox.AutoPostBack = true;
policies_ListBox.SelectedIndexChanged += new EventHandler(OnSelectedPolicyChanged);
confirmedEmployees_ListBox.EnableViewState = false;
pendingEmployees_ListBox.EnableViewState = false;
}
...
private void LoadPoliciesListBox()
{
foreach (SPListItem policyUpdate in policyUpdateLog_SPList.Items)
{
// Checking for duplicates before adding.
bool itemExists = false;
foreach (ListItem item in policies_ListBox.Items)
if (item.Text.Equals(policyUpdate.Title))
{
itemExists = true;
break;
}
if (!itemExists)
policies_ListBox.Items.Add(new ListItem(policyUpdate.Title));
}
}
Do some reading up on the Sharepoint web part life cycle. Properties are not updated until the OnPreRender event.
I am using the new AsyncFileUpload control from the latest AjaxControl ToolKit.
My query is regarding the OnClientUploadStarted event which is fired before the upload is started. Is there any way to cancel the upload, as I am checking the fileExtension at this point and would like to cancel the upload so that it does not continue and go on to upload the file. My end result is allow only images to be uploaded.
Please advise and thanks for your time.
Got the answer, all I had to do was override the javascript function with this script(not the best answer, but works), you all could have done faster and cleaner
var orig = AjaxControlToolkit.AsyncFileUpload.prototype.raiseUploadStarted;
AjaxControlToolkit.AsyncFileUpload.prototype.raiseUploadStarted = function(e) {
var evt = this.get_events()._getEvent('uploadStarted');
if (evt) {
if (evt.length > 1)
return orig(e);
else if (evt.length === 1)
return evt[0](this, e);
}
}
You might try adding a "Regular Expression Validator" to the field, and see if you can use that to validate the file selected before the upload starts.
Try this code:
protected void AsyncFileUpload1_UploadedComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
{
if (rdoFileType.SelectedValue == String.Empty)
{
lblStatus.Text = "Please select a file type before selecting a file.";
AsyncFileUpload1.FailedValidation = true;
e.state = AjaxControlToolkit.AsyncFileUploadState.Failed;
return;
}
try
{
// System.Threading.Thread.Sleep(5000);
if (AsyncFileUpload1.HasFile)
{
string _filename = System.IO.Path.GetFileName(e.filename);
System.IO.FileInfo f = new System.IO.FileInfo(AsyncFileUpload1.PostedFile.FileName);
if (rdoFileType.SelectedValue == "F")
{
if (f.Extension != ".pdf")
{
lblStatus.Text = "Final Document must be a .pdf";
e.state = AjaxControlToolkit.AsyncFileUploadState.Failed;
e.statusMessage = "Final Document must be a .pdf";
throw new Exception("Final Document must be a .pdf");
}