i have tried to close window(radWindow) using asp.net C#, but error on java script function is that 'object required' ,How can i solve this?
My java script and asp.net code is
<script type="text/JavaScript">
function Close() {
GetRadWindow().Close();
}
</script>
Asp.net code is
<asp:Button ID="btnSubmit" runat="server" Text="Submit Request" Height="27px" OnClick= "btnSubmit_Click" OnClientClick="Close();return false;" />
Optional try using C# for same operation as
C# code for button is
protected void btnSubmit_Click(object sender, EventArgs e)
{
//Server code
ScriptManager.RegisterStartupScript(this,GetType(), "close", "Close();", true);
}
You call GetWindow() but you don't have this function .
Just add this code ,
function GetWindow()
{
var oWindow = null;
if (window.radWindow) oWindow = window.radWindow;
else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow;
return oWindow;
}
This post may help you lot
http://www.telerik.com/community/forums/aspnet-ajax/window/getradwindow-close-cause-unspecified-error.aspx
i had same issues in the past but manged by the logic from the above post
Related
using asp.net | C#
I want my ImageButton to open a URL when I click it. I finally have my Image loading and it clicks but when I click it nothing happens. Here is the code I have so far:
aspx page
<asp:ImageButton ID="Button1" runat="server" ImageUrl="~/images/button.gif"
onclick="Open_Click"></asp:ImageButton>
aspx.cs page
protected void Open_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
try
{
System.Diagnostics.Process.Start("http://www.website.com");
}
catch { }
}
You want to do a redirect, not start a process. Try this:
protected void Open_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
try
{
Response.Redirect("http://www.website.com");
}
catch { }
}
Additionally, you could just set the PostBackUrl attribute on the control and have no need for a server side event.
You can do it on the client-side:
This will open in another window:
<asp:ImageButton OnClientClick="window.open('/xxx/xxx.aspx');
OR this will open in same window, javascript needs to return false so server code won't run:
<script>
function ReDirect() {
location.href = '/xxx/xxx.aspx';
return false;
}
</script>
asp:ImageButton OnClientClick="javascript:return(ReDirect());" />
I've got this button
<asp:Button runat="server" ID="btnReviewDocs" CssClass="btnReviewDocs" data-theme="b"
Text="Review Documents" OnClick="btnReviewDocs_Click" OnClientClick="clickHyperlink();"/>
And in 'OnClick' event I'm assembling an URL that I need to set to asp:Hyperlink and at the end of the 'OnClick' I'm setting this URL to the 'NavigateURL' propery of the 'asp:Hyperlink'. Once the 'asp:Hyperlink' has the correct URL I need to call the 'clickHyperlink()' function.
function clickHyperlink() {
var href = $('#hlnkID').attr('href');
if (typeof href !== "undefined") {
$.mobile.showPageLoadingMsg();
window.location.href = href;
}
}
But the 'OnClientClick' event is executed always before the 'OnClick'. Any suggestions for a workaround?
I'm doing all this stuff, because I've got problems with JQuery Mobile and 'Response.Redirect(url);' is changing the page, but not the URL.
I believe that you don't really need to involve the Hyperlink control in the JS part.
Modify your JS function and remove the OnClientClick attribute from the btnReviewDocs button:
<script type="text/javascript">
function clickHyperlink(href) {
$.mobile.showPageLoadingMsg();
window.location.href = href;
}
</script>
On the server, in the btnReviewDocs_Click method:
protected void btnReviewDocs_Click(object sender, EventArgs e)
{
// TODO: set the url, maybe append some params to the
// hlnkID.NavigateUrl value
var url = "http://stackoverflow.com/";
ClientScript.RegisterStartupScript(Page.GetType(),
"clickHyperlink",
"clickHyperlink('" + url + "');",
true);
}
Use the RegisterStartupScript in the ClientScript object to run the code after postback--->
protected void btn_Click(object sender, EventArgs e)
{
//some code
this.ClientScript.RegisterStartupScript(this.GetType(), "clintClick", "clickHyperlink", true);
}
try this
protected void btnReviewDocs_Click(object sender, EventArgs e)
{
//something doing here
Page.ClientScript.RegisterStartupScript(this.GetType(), "test", "<script type='text/javascript'>clickHyperlink()</script>");//call javascript function
}
The answer is mentioned by #Alex Filipovici.
But first you should ask yourself do you really need to go back to the client side to do a redirect ?
Why not call :
Response.Redirect("MyURL");
How to get input from user using a confirm box in asp.net and store the input in a C# variable.
as whether it is a ok or cancel button. pls help me forward.
For Example i am using like this,
Response.Write("confirm('Testing FiileAlready existing Replace it?')");
instead i need the output of the confirm box in c# variable...
Try this:
Your javascript function:
<script type="text/javascript" language="javascript">
function ConfirmOnReplace() {
if (confirm("Are you sure?") == true)
return true;
else
return false;
}
</script>
The ASP.NET button:
<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="return ConfirmOnReplace();" />
And the code-behind(YourPage.aspx.cs) file:
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Button1.Click += new EventHandler(Button1_Click);
}
void Button1_Click(object sender, EventArgs e)
{
// If you are here, your javascript method returned true
// TODO: Replace the file, or do what you want
}
}
i am having trouble catching errors in an AJAX panel. Even when i throw an exception in the c# code behind the front end completely ignores it.
Here is the code i have setup, can anyone see why?
I ideally want to show a js alert window on error.
Code Behind:
protected void btnX_Click(object sender, EventArgs e)
{
throw new ApplicationException("test");
}
protected void ScriptManager_AsyncPostBackError(object sender, AsyncPostBackErrorEventArgs e)
{
ScriptManager.AsyncPostBackErrorMessage = e.Exception.Message;
}
Markup:
<script type="text/javascript" language="javascript">
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
function EndRequestHandler(sender, e)
{
window.alert(e.get_error().name);
}
</script>
<asp:ScriptManager ID="ScriptManager" runat="server" AllowCustomErrorsRedirect="true" OnAsyncPostBackError="ScriptManager_AsyncPostBackError" />
I think you should be displaying the 'message' error property and not 'name'
see http://msdn.microsoft.com/en-us/library/bb383810.aspx
function EndRequestHandler(sender, e)
{
if (e.get_error() != undefined)
{
var errorMessage = e.get_error().message;
e.set_errorHandled(true);
alert(errorMessage)
}
}
I am using asp.net 3.5 with C#. I need to do a database lookup when a user enters ProductID in txtProductID. I guess doing javascript is out of the question since this will have to be server side call.
I wrote this code in the page_load event of the webpage:
protected void Page_Load(object sender, EventArgs e)
{
txtProductID.Attributes.Add("onblur", "LookupProduct()");
}
protected void LookupProduct()
{
//Lookup Product information on onBlur event;
}
I get an error message: Microsoft JScript runtime error: Object expected
How can I resolve this ?
onblur is a client-side event. LookupProduct is a server-side method. You can't reference one from the other - there's simply no association whatsoever between the two.
There's no quick fix for this - you have to either trigger a postback on the client event (using ClientScriptManager.GetPostBackEventReference) or implement an Ajax callback using a library like Microsoft ASP.NET Ajax.
Alternatively, if you don't really need to fire this event on every blur, and only when the text has changed, then you can simply use the server-side TextBox.OnChanged event and set the TextBox's AutoPostBack property to true. Make sure you remember to set AutoPostBack, otherwise this won't get you anywhere.
Use the TextBox.TextChanged event.
ASPX markup:
<asp:TextBox ID="txtProductID" runat="server" AutoPostBack="true" OnTextChanged="txtProductID_TextChanged" />
Codebehind:
protected void txtProductID_TextChanged(object sender, EventArgs e)
{
// do your database query here
}
This should do the trick, as referenced here: http://www.codedigest.com/CodeDigest/80-Calling-a-Serverside-Method-from-JavaScript-in-ASP-Net-AJAX---PageMethods.aspx
These are the controls
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="True" />
<asp:TextBox ID="txtTest" onblur="LookupProduct()" runat="server" />
This is the Javascript
<script language="javascript">
function LookupProduct()
{
PageMethods.LookupProduct('',OnSuccess, OnFailure);
}
function OnSuccess(result) {
if (result)
{
}
}
function OnFailure(error) {
}
</script>
This is the server sidewebmethod
[WebMethod]
public static bool LookupProduct()
{
return true;
}