Hello all,
I have an ultrawebgrid that has many rows and many columns. On the Task column, I have embedded an asp.net 2.0 LinkButton and in there I have the link to open up a .aspx modal. The modal does opens up on the second click on the Link Button. After the first click it seems to initialize the link opens up the modal and after that when I tried to opens up the modal again on that same row, it will open up on the first click. And if I were to go onto the second row and click the link for the first time, it would not open up the modal, but on the second click, third click , and so on (on that second row), then it will open up the modal.
So my question is, how do I initialize the link to the modal on either Page_Load, InitializeLayout or InitializeRow event methods. I have tried it on all three but none of them work because it cannot find the instance of my asp.net LinkButton.
It seems like, it will only initialize the modal link when it invoke the LinkButton1_Click event.
LinkButton1_Click (object sender, EventArgs e)
{
//Create an instance of the LinkButton
LinkButton lnkButton = (LinkButton) sender;
//some javascript function
script = "javascript code here";
Page.ClientScript.RegisterStartupScript(typeof(Page), "modalDlg", script);
lnkButton.Attributes.Add("onClick", "doIt();"); // doIt(); is the javascript function from the "script" block two lines above
}
I have tried using FindControls ("LinkButton1") but it cannot find it in neither Page_Load, InitializeLayout or InitializeRow.
If someone knows how to solve this, please shred some light on me.
Thanks very much in advance!
Hs2
Hi,
If you don`t mind can you send code for me. last two weeks iam tring to implemented same functionlities. but i can`t please help me.
Hello,
Sorry for replying so late b/c i wasn't able to check email.
Design:
What you need to do is actually really simple: In your webgrid, create a templatedcolumn and use an asp:LinkButton
<igtbl:TemplatedColumn AllowUpdate="No" Key="TestColumn"> <CellTemplate> <asp:LinkButton ID="lBtnTest" runat="server" Text="Test" OnClick="lBtnTest_Click" /> </CellTemplate> <Header Caption="Test Column"> <RowLayoutColumnInfo OriginX="9" /> </Header> <Footer> <RowLayoutColumnInfo OriginX="9" /> </Footer> </igtbl:TemplatedColumn>
C# Code in behind:
In your C# code, you inside the linkbutton event,
protected void lBtnTest_Click(object sender, EventArgs e){
string sScript = null;
string sHeight = 400px; // or whatever size you want your modal to be
string sWidth = 400px; // or whatever size you want your modal to be
//If you need to pass any data to the modal then do it in the line below after the sTitle variable
sScript = "<script>var rc=new Array(0,0); rc=window.showModalDialog('Test.aspx?Title=" + sTitle + "','','dlgHeight:" + sHeight + " px;dlgWdith:" + sWidth + " px');" + "\n";
//this line of code handle the case where I want to return a value back to parent screen from the modal sScript += "if(rc!=null){document.getElementById('returnvaluetoparentscreen').innerText=rc[0]; __doPostBack('','');}</script>";
//This line of code register the script
this.ClientScript.RegisterStartupScript(typeof(Page), "showModalDialog", sScript);
If you just take this code and follow my example, it should give / invoke the modal and whatever you need to pass to the modal, you can do it after you can get it to invoke.
Let me know if you need futher help.
HS2