Category Archives: Jquery

[RESOLVED] Loading please wait in VB.NET while gridview loads data

Hi,

I am trying to display the loading please message or a spinning image while a page loads data in a gridview. Users click on a link from one page and get redirected to another page via the response.redirect method. The new page loads some data in a gridview based upon some variables passed. Some times it could take up to 20+ seconds for the gridview to load. I have displayed loading please wait message previously using the jQuery, Post and ajax methods etc. In this case it's just straight VB.NET code that makes a sql connection to the server, executes a stored procedure and binds the returned data to the gridview. I would like the message or image to start showing once they click on the link to get redirected to the new page and continue to display till the gridview data has been loaded. Here is an example of the code:

Try
Dim cmd As SqlCommand = New SqlCommand("CustOrderHist", New SqlConnection("Server=localhost;Database=Northwind;Trusted_Connection=True;"))
cmd.CommandType = Data.CommandType.StoredProcedure
cmd.Parameters.AddWithValue("CustomerID", txtCustID.Text)
cmd.Connection.Open()
gvwExample.DataSource = cmd.ExecuteReader()
gvwExample.DataBind()
cmd.Connection.Close()
cmd.Connection.Dispose()
Catch ex As Exception
lblStatus.Text = ex.Message
End Try



Thanks

To avoid the loading time. What you can do is lazy load the gridview after the page is loaded using Updatepanel and Timer

This way your page will be loaded while the gridview will be populated later.

http://www.aspsnippets.com/Articles/Delay-Load-Lazy-Load-UpdatePanel-using-Timer-Control-in-ASP.Net.aspx 

Thank you, this trick seemed to work great for me.

[RESOLVED] onclientClick before OnServerClick

hi,

 i would like to do the validation work using javascript or jquery in onclientclick and then show blockUI , next page using server click.

but, i have a captcha validation in server click and i do'nt know how to validate the captcha in jquery or javascript.

    protected void btnRegister_Click(object sender, EventArgs e)
    {        
        lblMessage.Text = "";
        if (Page.IsValid)
        {
            if (txtUserName.Text == "")
            {
                lblMessage.Text = "نام کاربری را وارد نمائید";
                txtUserName.Focus();
                return;
            }
            if (!BLL.IsStrictPassword(txtPassword.Text))
            {
                lblMessage.Text = "طول کلمه عبور حداقل باید 5 کاراکتر باشد";
                txtPassword.Focus();
                return;
            }
            if (ddlYear.Text == "<سال>" || ddlMonth.Text == "<ماه>" || ddlDay.Text == "<روز>")
            {
                lblMessage.Text = "لطفا تاریخ تولدتان را وارد نمائید";
                return;
            }
            if (!chk_Low.Checked)
            {
                lblMessage.Text = "برای عضویت می بایست قوانین سایت را بپذیرید";
                return;
            }
            if (txtSecurityCode.Text == String.Empty)
            {
                lblMessage.Text = "کد امنیتی را وارد نکرده اید";
                txtSecurityCode.Focus();
                return;
            }
            secCode.ValidateCaptcha(txtSecurityCode.Text);
            if (!secCode.UserValidated)
            {
                lblMessage.Text = "کد امنیتی نادرست وارد شده است";
                return;
            }
            try
            {
//some code
}
}

I don't know the answer, but why don't you use the ASP.NET validation controls? They run on the client and will handle much of this for you.

At the end of your client validation function defined in the button's "onclientclick" attribute either return true (validation success, go on with the postback) or false (validation not successful, halt all other javascript functions)

actually if you use the asp.net validation controls you will be using JavaScript automatically because they will generate javascript validation code and insert it to your pages html code at runtime.

hi

thanks for all replys.

but my main problem is captcha validation.as i said before,i have a piece code in server click that validate the captcha.

i use the asp.net validation for other controls in the page,but what i do for captcha, or how to communicate between client and server click.

thanks a lot


[RESOLVED] Load another page without page refresh.

I have 2 pages (test1.aspx & test2.aspx). I have one button in test1.aspx, on click of it, I am loading test2.aspx, like Response.Redirect("test2.aspx"). It refreshes the browser/ page and load test2.aspx.

What I have to do is, I have to load test2.aspx without any page/ browser refresh.

 

 

Thanks,

Whenever any brand new page loads , it will refresh the browser.

You may develop  test2.aspx in a UserControl & load it in a UpdatePanel

That I know. I can use iframe too and can set the source of iFrame to test2.aspx, but I am looking for solution without iframe or UserControl.

 

Thanks, 

Not sure but i think ive done something like that with javascript before without it posting back the page

'Build a javascript alert
                'please note the peculiar '/script' in the last line of the script string
                'This is to work around the problem that compiler would mistake the
                'closing script tag as the outer script closing tag.
                Dim sb As System.Text.StringBuilder = New System.Text.StringBuilder
                sb.Append("<script language='javascript'>")
                sb.Append("window.open('alertsAgent.aspx?MU_ID=" & MU_IDstring.ToString & "&Site=" & SiteString.ToString & "&firstname=" & firstnameString.ToString & "&surname=" & surnameString.ToString & "&username=" & usernameString.ToString & "', 'Alerts', 'width=680,height=300,fullscreen=no,scrollbars=1,resizable=0,status=1,dependent=yes,alwaysRaised=yes');{ self.close() };<")
                sb.Append("/script>")


                'register with ClientScript


                Dim t As Type = Me.GetType
                If Not ClientScript.IsClientScriptBlockRegistered(t, "redirectAgentScript") Then
                    ClientScript.RegisterClientScriptBlock(t, "redirectAgentScript", sb.ToString)
                End If


 

You need to take advantage of ASP.NET Ajax partial page refreshing, or use iFrame inside your page to trigger the test2.spx inside your test1.aspx.

Or may be try using JQuery/JTemplate/JSON to load a page w/o flicker. 

Try like this...use HttpWebRequest class, get the html response and then make a jquery call to this function and try to replace the complete form with the html content which you get to jquery....

i never tried it....but there might be performance concerns, i dont know yet...but it might work...

PS - have you tried MultiView control...look at that may be it might fit your requirement...

Thanks.

function LoadPage() {
            window.location = "test2.aspx";
            return false;
        }


// call this function by button client clcik




 <asp:Button ID="btnClick" runat="server" OnClientClick="return LoadPage();" />


You can achieve this same things by javascript function with below code.

[RESOLVED] Passing Array or Object to Javascript Function using ICallbackEventHandler

How would I pass an Object or Array to a function using the ICallBackEventHandler (RaisCallbackEvent)? It allows for a string argument only, if you change it to another datatype it error out. Sample Below...

Public Class _Default
    Inherits System.Web.UI.Page
    Implements ICallbackEventHandler
    Public _callbackResult As String = Nothing


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim cbReference As String = Page.ClientScript.GetCallbackEventReference(Me, "arg", "GetDateFromServer", "context")
        Dim cbScript As String = "function UseCallback(arg,context)" & _
        "{" & cbReference & ";" & "}"
        Page.ClientScript.RegisterClientScriptBlock(Me.GetType(), "UseCallback", cbScript, True)
    End Sub


    Public Function GetCallbackResult() As String Implements System.Web.UI.ICallbackEventHandler.GetCallbackResult
        Return _callbackResult
    End Function


    Public Sub RaiseCallbackEvent(ByVal eventArgument As String) Implements System.Web.UI.ICallbackEventHandler.RaiseCallbackEvent
        _callbackResult = Now.ToString
    End Sub


End Class

 

<script language="javascript">
    function GetDate() {
        UseCallback();
    }
    function GetDateFromServer(arg, context) {
        var control = document.getElementById('MainContent_TextBox1');
        control.value = arg
    }
</script>


 

 

 

I dont think you can pass objects...this is from MSDN - 

"Note that the arguments sent between the client script and the server code can only be strings. To pass in or to receive multiple values, you can concatenate values in the input or return string, respectively."

In this case you can use JQuery with Get or POST request....

http://www.intstrings.com/ramivemula/articles/jquery-post-get-request-to-wcf-service-in-asp-net-mvc/

Thanks.

ramiramilu

I dont think you can pass objects...this is from MSDN - 

 

I've been doing some more reseach and came up with the following possible options:

1) doPostBack

2) HiddenField

3) ICallbackEventHandler

4) Page.RegisterClientScriptBlock

I am trying to create samples of each to see which one may be most effective for my situation. Question for someone out there...I basically need an "onfocus" event wired to each dynamic control in a webpage. When the users puts focus on any control, code needs to run on the server to run additional script from a database then return the results to applicable dynamic controls on the web page. How to best do this?

JQuery...

AJAX....Update Panel....

those are best....

Even though you can make this with JAvascript....I would say go for AJAX....because Javascript is clientside code only....but AJAX lays on the Http pipeline itself....os i consider it more efficient....

Thanks. 

ramiramilu

JQuery...

AJAX....Update Panel....

 

I currently am using ajax update panels and can do everything fine with the control server side events like (TextChanged) but I need an onfocus event which is only client side. I need server side code to run when the onfocus is fired.

I dont know whether you are looking at JQuery which I am mentioning from my initial post....you can handle onfocusin, onfocusout, onfoucs events.....

Thanks.

 You may use ClientScript.RegisterArrayDeclaration to work w/ arrays

Here's an example

//aspx
<script language="javascript" type="text/javascript">
        function iterateArray() {
            for (var i = 0; i < newpoints.length; i++) {
                var currentValue = newpoints[i];
                $get("results").innerHTML += '<br>#' + i + ': ' + newpoints[i];
            }
        }
    </script>


//codebehind
//2 examples here

private void ArrayToGoClientSide()
    {
        string clientSideArrayName = "newpoints";
        string arrayString = string.Empty;
        for (int i = 0; i < 6; i++)
        {
            if (arrayString.Length > 0)
                arrayString += ",";

            arrayString += "'" + "test"+ i.ToString() + "'";
        }
        ClientScript.RegisterArrayDeclaration(clientSideArrayName, arrayString);
    }


    private void ArrayToGoClientSide2()
    {
        String arrName = "MyArray";
        String arrValue = "\"aaaa\", \"sssss\", \"icon0\", \"title\", \"description\"";
        String csname1 = "PopupScript";
        String csname2 = "ButtonClickScript";

        if (!Page.ClientScript.IsClientScriptBlockRegistered(csname1))
        {
            String cstext1 = "<script type=\"text/javascript\">" +
                "alert('Hello World');</" + "script>";
            Page.ClientScript.RegisterStartupScript(this.GetType(),csname1, cstext1);
        }

        if (!Page.ClientScript.IsClientScriptBlockRegistered(csname2))
        {
            StringBuilder cstext2 = new StringBuilder();
            cstext2.Append("<script type=\"text/javascript\"> function DoClick() {");
            cstext2.Append("Form1.Message.value='Text from client script.'} </");
            cstext2.Append("script>");
            Page.ClientScript.RegisterClientScriptBlock(this.GetType(),csname2, cstext2.ToString());
        }

    }


 

[RESOLVED] redirect on etxtbox text change

how to response.redirect on textbox etxt change event to another page.


use following code

<asp:Textbox runat="server" id="btnTest" onkeypress="javascript:window.open('newpage.aspx', '_self');">

protected void TextBox1_TextChanged(object sender, EventArgs e)
    {
        string url = "yourpagename";//default.aspx;
        Response.Redirect(url);
        //or
        Server.Transfer(url);
    }



i have a autocomplete.when i select anyvalue from the autocomplete list..it appers on the textbox now this it the time when i want to response.redirect.r u getng the point?


aha even if u have an AutoComplete-Box try to Redirect on Click on Button..

protected void Button2_Click(object sender, EventArgs e)
    {
        TransValue(TextBox1.Text);
    }


    private void TransValue(string p)
    {
        if (p != null)
        {
            string url = "yourpagename?";//default.aspx;
            url += "MyValue=" + Server.UrlDecode(p);
            Response.Redirect(url);
            

        }
     

    }


yes id did that. but i want on etxtchange also.

Hi ogsim07, 

If you use the jquery autocomplete, you can set the  selectItem for the control.

And use the window.open to open a new window.

Please check the following link:

http://www.pengoworks.com/workshop/jquery/autocomplete.htm

If you use autocomplete toolkit toolkit, you use the sys.application to append the selectitem event for it.

And register the javascript for it.