在Asp.net c#on按钮点击事件(服务器端) [英] In Asp.net c# on button click event (server side)

查看:66
本文介绍了在Asp.net c#on按钮点击事件(服务器端)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Asp.net c#on按钮点击事件(服务器端)我需要在添加按钮单击时使用javascript方法清除表单上的所有文本框,然后我需要将服务器端的值设置为textbox,如下所示。

但是如果我评论注册脚本行然后它工作但是我还需要清除文本框它不起作用。

In Asp.net c# on button click event(server side) I need to clear all textbox on the form using javascript method on add button click and then I need to set value to textbox by serverside as given bellow.
But it is not working if I comment registering script line then it working but I also need to clear the textboxes.

protected void btnAdd_Click(object sender, EventArgs e)
 {  
    ScriptManager.RegisterStartupScript(this, typeof(string), "key1","ClearControls();",                    true);
    TxtChallanNo.Text = "New";
  }



使用上面的代码添加按钮后点击事件文本框保持为空,我希望将其设置为新

谢谢提前。


Using above code after add button click event textbox remain empty, I expect to set it to "New"
Thanks in advance.

推荐答案

你必须指定TxtChallanNo.Text =New;进入你的javasScript函数,即ClearControls();你的执行代码是错误的,因为当你调用以下行时



ScriptManager.RegisterStartupScript(this,typeof(string),key1,ClearControls();,true );



当你执行你的javascript代码时按钮点击执行完成时,它不会执行它。有关此内容的更多信息,请在按钮单击时插入断点以及javascript函数,然后检查代码的执行方式。
You have to assign TxtChallanNo.Text = "New"; into your javasScript function i.e. ClearControls(); your executing code wrongly because when you call the following line

ScriptManager.RegisterStartupScript(this, typeof(string), "key1","ClearControls();", true);

it does not execute it that time itself when your button click execution completed that time it execute your javascript code. For more information about this please insert breakpoint on button click as well as javascript function then check how your code get executed.


有很多方法可以在代码后面调用JS函数,其中一个是:

There are many ways to call JS function in code behind, one of them is:
protected void MyButton_Click(object sender, EventArgs e)
    {
        Page.ClientScript.RegisterStartupScript(this.GetType(), "myScript",           "SomeJSFunction();", true);
        textID.Text =SomeFunction();
        textName.Text = "SomeRandomeText";
    }
    public String SomeFunction()
    {
        count += 1;
        return count.ToString();
    }



试试这个,它会对你有用。

谢谢


Try this , it will work for you.
Thanks


这篇关于在Asp.net c#on按钮点击事件(服务器端)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆