windows.onload() popup is not showing entire message in chrome. In explorer popup is showing full message. How to resolve this issue in Chrome?
tried in explorer popup is showing full msg . how to resole this issue in chrome
string script = "window.onload = function() { alert('" + message + "'); };";
ClientScript.RegisterStartupScript(this.GetType(), "alert", script, true);
protected void Page_load(object sender,EventArgs e)
{
string message="hii";
Response.Write("<script type='text/javascript'>alert('"+message+"');</script>");
}
Try this one...
Related
I have a java date picker and it is not passing back the value in chrome. I think its is due to the js using window.returnvalue. How would i fix this?
// Allow the browser to save/pass the date selected and close the window.
protected void calDate_SelectionChanged(object sender, System.EventArgs e)
{
string closeWindow = #"
<script language='javascript'>
window.returnValue='###date###';
window.close();
</script>";
closeWindow = closeWindow.Replace("###date###", calDate.SelectedDate.ToShortDateString());
ClientScript.RegisterStartupScript(this.GetType(), "CloseWindow", closeWindow);
}
Beginner here, so please be gentle.
I'm trying to ask the User for confirmation. When he accepts, my javascript invokes a Button to run some code behind. The code behind will run a JavaScript function which alerts, just so I can see if it all works. What happens is, that after my first confirm() dialog, a second dialog appears. After confirming again, the code runs and my second JavaScript function confirms by alerting. But after I press okay on that, the whole thing jumps back to my first function and I get into a loop!
ASPX:
<script type = "text/javascript">
function ConfirmComputerOverwrite(ComputerName) {
if (confirm("Overwrite present computer " + ComputerName + " ?"))
{
}
else
{
}
document.getElementById("Test").click()
}
function allworkedout()
{
alert("asdf");
}
Code behind:
public string ComputerName = "";
protected void Page_Load(object sender, EventArgs e)
{
string ComputerName = "Computer1";
this.ComputerName = ComputerName;
StringBuilder sb = new StringBuilder();
sb.Append("ConfirmComputerOverwrite('" + ComputerName + "');");
ScriptManager.RegisterStartupScript(this, GetType(), "ConfirmComputerOverwrite", sb.ToString(), true);
}
protected void Test_Click(object sender, EventArgs e)
{
StringBuilder sb = new StringBuilder();
sb.Append("allworkedout();");
ScriptManager.RegisterStartupScript(this, GetType(), "allworkedoutID", sb.ToString(), true);
}
Thanks in advance !
Unless you are using ajax, the whole page is reloaded after click, so your javascript is executed again, prompting for confirmation, etc...
I have below code which I am using to open a new window up on buttonclick. I am executing below code in button click event : New windows opens up but it does not focus, it just goes behind the main page.... please how can I fix this issue....
protected void btnView_Click(object sender, EventArgs e)
{
int activeTab = pgSearchFrm.ActiveTabIndex;
string sel = this.ddlFields.SelectedValue;
string url = "\\ATPrintView.aspx?SearchID=" + Convert.ToString(activeTab) + "&Col=" + sel + "&Val=" + txtFields.Text;
ScriptManager.RegisterStartupScript(this, this.GetType(), "Open", "window.open('" + url + "','_blank','height=500,width=800,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=no,titlebar=no').focus();", true);
}
I have a new page with the following:
The Response.Redirect works, but I don't get a popup before hand...
Any ideas???
protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString["timeout"] != null && Request.QueryString["timeout"].ToString().Equals("yes"))
{
Response.Write("<script>alert('Your Session has Timedout due to Inactivity');</script>");
Response.Redirect("Default.aspx");
}
}
The Response.Redirect call never returns the code to the user. It immediately redirects the user to the next page. From the MSDN on Response.Redirect: "Any response body content such as displayed HTML text or Response.Write text in the page indicated by the original URL is ignored."
The Response.Redirect redirects the browser and your JavaScript does not get executed.
Try redirecting in JavaScript instead:
protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString["timeout"] != null && Request.QueryString["timeout"].ToString().Equals("yes"))
{
Response.Write("<script>" +
"alert('Your Session has Timedout due to Inactivity');" +
"location.href='Default.aspx';" +
"</script>");
}
}
Okay, I've gotten a unique issue I've been trying to solve for two days.
I have System.Web.UI.WebControls.WebParts.WebPart control I am building a custom Sharepoint View with. Almost everything I want done is working except one little issue. I need to use Javascript to Format Date and Currency fields. The Client wants DateTime fields to be mm/dd/yyyy and currency have $ and commas where appropriate.
This is easy enough in javascript on a regular aspx page. I just wrote the functions and on page load
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GridFieldDAO dao = new GridFieldDAO();
myGrid.DataSource = dao.getItems();
myGrid.DataBind();
}
GetBuildFormattingScript();
}
private void GetBuildFormattingScript()
{
string script = "<script type=\"text/javascript\">";
script += " FormatByRows(\"" + myGrid.ClientID + "\",2);";
script += " FormatByRowsDate(\"" + myGrid.ClientID + "\",1);";
script += "</script>";
if(!ClientScript.IsClientScriptBlockRegistered("DoFormatting"))
ClientScript.RegisterStartupScript(typeof(string), "DoFormatting", script);
string script2 = " <script type=\"text/javascript\">"+
"var prm = Sys.WebForms.PageRequestManager.getInstance(); "+
"prm.add_beginRequest(BeginRequestHandler); "+
"prm.add_endRequest(EndRequestHandler); "+
"function BeginRequestHandler(sender, args) "+
"{ }"+
"function EndRequestHandler(sender, args) "+
"{ FormatByRows(\"" + myGrid.ClientID + "\",2); "+
" FormatByRowsDate(\""+myGrid.ClientID+"\",1);}</script> ";
if (!ClientScript.IsClientScriptBlockRegistered("DoUpdateFormatting"))
ClientScript.RegisterStartupScript(typeof(string), "DoUpdateFormatting", script2);
}
My issue in that on the OnLoad of the WebPart the grid I am wanting to update doesn't exists... so I have to add code to the OnPreRender.
Well, the WebPArt loads and the Javascript doesn't fire... so I click refresh and it does fire. Can anyone help me get the code working on the inital WebPart Load? Has anyone been able to get server side script to work this way in SharePoint?
Thanks,
Mike V
For this, you can take advantage of _spBodyOnLoadFunctionNames:
string script = "<script type=\"text/javascript\">";
script += " function FormatDataGridRows() {";
script += " FormatByRows(\"" + myGrid.ClientID + "\",2);";
script += " FormatByRowsDate(\"" + myGrid.ClientID + "\",1);";
script += " }";
script += " _spBodyOnLoadFunctionNames.push('FormatDataGridRows');";
script += "</script>";
Edit
To test, put the following code in a Content Editor web part on your page:
<script type="text/javascript">
function SayHello() {
alert('hello world!');
}
_spBodyOnLoadFunctionNames.push("SayHello");
</script>