Issue with Clientscript Registerstartupscript
I am using a script code on C# , asp.net2.0. What i want is to generate a report in new window on a click but its doing so, neither gives any error. Do any of you have any suggestion or idea about the same ? The code is here:-
Quote:
string Script= "<script type='text/javascript' language ='javascript' >";
Script+= "window.open('PasswordRecovery.aspx',null,'resizeable=no,scrollbars=no,addressbar=no,toolbar=no,widt h=300,Height=250');";
Script+= "</script>";
Type csType = this.GetType();
Page.ClientScript.RegisterStartupScript(csType, "PopupScript", Script);
Re: Issue with Clientscript Registerstartupscript
I tried this, but it is working fine. I guess there must be some thing else wrong with you.I think u had given wrong file name. i'll suggest to check your code. Passing url for PasswordRecovery.aspx file name. Or just try this:-
Quote:
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
string myScript = @"alert(document.forms[0]['TextBox1'].value);";
Page.ClientScript.RegisterStartupScript(this.GetType(),
"MyScript", myScript, true);
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server" Text="Hello ASP.NET"></asp:TextBox>
</div>
</form>
</body>
</html>
Re: Issue with Clientscript Registerstartupscript
Or simply try this code, you will not need RegisterStartupScript for this task.
Quote:
<%@ Page Language="C#" AutoEventWireup="true" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Page_Load()
{
StringBuilder sb = new StringBuilder();
sb.Append("var box1 = document.getElementById('");
sb.Append(TextBox1.ClientID);
sb.Append("');");
sb.Append("var box2 = document.getElementById('");
sb.Append(TextBox2.ClientID);
sb.Append("');");
sb.Append("if (box1 != null && box1.value.length == 5 && box2 != null)");
sb.Append("{");
sb.Append("box2.focus();");
sb.Append("}");
TextBox1.Attributes.Add("onkeyup", sb.ToString());
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server" />
<asp:TextBox ID="TextBox2" runat="server" />
</div>
</form>
</body>
</html>
Or try this :
Quote:
string Script = "window.open('PasswordRecovery.aspx',null,'resizeable=no,scrollbars=no,addressbar=no,toolbar=no,widt h=300,Height=250')";
Type csType = this.GetType();
Page.ClientScript.RegisterStartupScript(csType, "PopupScript", Script, true);
Re: Issue with Clientscript Registerstartupscript
Did not get to .net 2 yet, but try Response.Write(myscript)