将aspx中的值传递给aspx.cs [英] Passing value in aspx to aspx.cs

查看:126
本文介绍了将aspx中的值传递给aspx.cs的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用javascript在aspx中创建表单以创建用于选择日期的日历.
如何将日期输入aspx.cs?

Have a form in aspx using javascript to create a calendar for date selection.
How to I get the date into the aspx.cs? Using sql in the aspx.cs to get data based on the start and end date.

推荐答案

使用
ICallbackEventHandler


前面:
< script> CallServer(转义(您要转移的值))</script>
背景:


front:
<script>CallServer(escape(Value you want to transfer))</script>
background:

public partial class Work_RiZhi : System.Web.UI.Page, ICallbackEventHandler{
        string returnvalue;
 protected void Page_Load(object sender, System.EventArgs e)
    {
             string CallbackScript = @"
        function CallServer(arg) {
         " + ClientScript.GetCallbackEventReference(this, "arg", "ReceiveServerData", null) + @";
        }
        ";
        ClientScript.RegisterClientScriptBlock(this.GetType(), "CallServer", CallbackScript, true);
    }
 public void RaiseCallbackEvent(string eventArgument)
    {
        if (eventArgument != string.Empty)
        {
getData(eventArgument);
}}
      public string GetCallbackResult()
    {
        return returnvalue;
    }
private string getData(string ID)
{
    retrun "new "+id;
}




根据我的理解,您需要获取使用Javascript完成的日期控件的值.在回发页面上,您需要在cs页面中具有此值,然后从SQL获取该值.

解决方案

在这种情况下,请在页面上放置一个隐藏字段.

Hi,

As per my understanding you need to get the value of a date control which you have done using Javascript. On the post back you need to have this value in cs page and then get the value from SQL.

Solution

In this case please put a hidden field in the page.

<asp:hiddenfield id="hdValue" runat="server" xmlns:asp="#unknown" />



然后使用Javascript将值分配给选定的隐藏字段.



Then assign the value to the hidden field on selection using Javascript.

document.getElementById('hdValue').value = '<< Selected value from calender>>';


在回发时,您可以从隐藏字段中获取值.


如果您希望在不回发的情况下刷新数据,则需要使用Call Back或Ajax.

希望这会有所帮助.


On post back you can get the value from the hidden field.


In case if you looking for data to be refreshed without postback then need to go for Call Back or Ajax.

Hope this helps.


这篇关于将aspx中的值传递给aspx.cs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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